msf4j Runnable / Thread

时间:2018-02-21 10:14:18

标签: java msf4j wso2msf4j

我尝试让我的msf4j jar变为runnable(公共类abcService实现Runnable,Microservice) 当我将jar部署到wso2 msf4j容器时,runnable部分不能作为“主线程”工作,并且“子线程”不会显示在控制台上。

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 个答案:

答案 0 :(得分:0)

我相信你想把你的问候服务作为服务器运行吗?如果是这样,只需创建一个MicroservuceRunner并将服务实例传递给它并运行它。你没有实现Runnable 请参阅MSF4J repository

中的helloworld示例

基本上应该如下

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