首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >msf4j可运行/线程

msf4j可运行/线程
EN

Stack Overflow用户
提问于 2018-02-21 18:14:18
回答 1查看 77关注 0票数 0

我试图使我的msf4j jar成为可运行的(公共类abcService实现Runnable,微服务)当我将jar部署到wso2 msf4j容器时,runnable部分不能作为“主线程”工作,并且“子线程”不显示在控制台上。

代码语言:javascript
复制
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!");
}
}
EN

回答 1

Stack Overflow用户

发布于 2018-02-27 04:42:00

我相信你想把你的问候服务作为一个服务器来运行,对吧?如果是这样的话,只需创建一个MicroservuceRunner并将您的服务的一个实例传递给它,然后运行它。您不必实现Runnable,请参考MSF4J repository中的helloworld示例

基本上,它应该如下所示

代码语言:javascript
复制
new MicroservuceRunner().deploy(new abcService()).start();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48903281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档