0
votes

I try to make my msf4j jar become runnable (public class abcService implements Runnable, Microservice) When i deployed the jar to wso2 msf4j container, the runnable part is not working as "Main thread " and "Child Thread " is not displayed at the console.

package test.msf4j.abc;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.wso2.msf4j.Microservice;

@Path("/abcService")
public class abcService implements Runnable, Microservice {

@GET
@Path("/greeting")
public String message() {
    System.out.println("hello");
    return "Hello World";
}

public void run() {
    for (int i = 0; i < 3; i++) {
        System.out.println("Child Thread ");
        try {
            Thread.sleep(200);
        } catch (InterruptedException ie) {
            System.out.println("Child thread interrupted! " + ie);
        }
    }
    System.out.println("Child thread finished!");
}

public static void main(String[] args) {
    Thread t = new Thread(new abcService ());
    t.start();
    for (int i = 0; i < 3; i++) {
        System.out.println("Main thread ");
        try {
            Thread.sleep(200);
        } catch (InterruptedException ie) {
            System.out.println("Child thread interrupted! " + ie);
        }
    }
    System.out.println("Main thread finished!");
}
}
1
Share the complete snippetYati Sawhney
@YatiSawhney updatedGOAT_Dirk
I believe you aren't invoking the main hence the statements are not getting printed And what's the point of having a main method in a restful resource or service layer?Yati Sawhney
What you mean by wso2 msf4j container? Why do you wanna implement runnable here? I believe you wanna run your greeting service as a server right? If so just create a MicroservuceRunner and pass a instance of your service to that and run that. You don'thave to implement RunnableThusitha Thilina Dayaratne
yes, any sample for MicroserviceRunner?GOAT_Dirk

1 Answers

0
votes

I believe you wanna run your greeting service as a server right? If so just create a MicroservuceRunner and pass a instance of your service to that and run that. You don'thave to implement Runnable Refer the helloworld sample in MSF4J repository

Basically it should be as follows

new MicroservuceRunner().deploy(new abcService()).start();