0

我尝试让我的 msf4j jar 变为可运行(公共类 abcService 实现可运行、微服务)当我将 jar 部署到 wso2 msf4j 容器时,可运行部分无法作为“主线程”工作,并且“子线程”未显示在控制台上.

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!");
}
}
4

1 回答 1

0

我相信您想将问候服务作为服务器运行,对吗?如果是这样,只需创建一个MicroservuceRunner并将您的服务实例传递给它并运行它。您不必实现参考MSF4J 存储库Runnable 中的 helloworld 示例

基本上应该如下

new MicroservuceRunner().deploy(new abcService()).start();
于 2018-02-26T20:42:00.380 回答