简体   繁体   English

JZMQ错误:无可用线程

[英]JZMQ error: no thread available

I'm trying to write a simple java application that would run on a server and do some simple stuff. 我正在尝试编写一个可以在服务器上运行并执行一些简单操作的简单Java应用程序。 But currently my application is failing on a weird error i cannot seem to find any information on Exception in thread "main" org.zeromq.ZMQException: No thread available(0x9523dfe) 但是当前我的应用程序由于一个奇怪的错误而失败,我似乎无法Exception in thread "main" org.zeromq.ZMQException: No thread available(0x9523dfe)找到有关Exception in thread "main" org.zeromq.ZMQException: No thread available(0x9523dfe)任何信息Exception in thread "main" org.zeromq.ZMQException: No thread available(0x9523dfe)

Both services run on the same server, but only my application is failing. 两种服务都在同一台服务器上运行,但是只有我的应用程序出现故障。 I have found only minimal documentation for the C zmq framework. 我发现C zmq框架的文档很少。 Nothing for java. Java没什么。

The class where the error occurs: 发生错误的类:

public class TestService extends GenericService {

public TestService(String[] args) {
    init(args);
}

private void init(String[] args) {
    int i = 0;
    serviceId = args[i++];
    servicePort = Integer.valueOf(args[i++]);
}

private void retrieveConfig() {

}

public void run() {
    System.out.println("Running");
    initZmq(); // <---- Here
    retrieveConfig();
    for (int i=0; i<120; i++) {
        System.out.println("Counter = " + i);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
    }
    closeZmq();
    System.out.println("Done!");
}

@Override
protected void requestInit() {
    zmqClient.send(getInitMessage().getBytes(),0);
    byte[] reply = zmqClient.recv(0);
    System.out.println("Config - " + (new String(reply)));
}

}

Abstract generic service class. 抽象的通用服务类。

public abstract class GenericService {

protected Context zmqContext;
protected Socket zmqClient;
protected int port;
protected int servicePort;
protected String serviceId;

protected static final String addressNoPort = "tcp://127.0.0.1:";

public GenericService() {}

protected void initZmq() {
    zmqContext = ZMQ.context(0);
    zmqClient = zmqContext.socket(ZMQ.REQ);
    zmqClient.connect(getAddress());
}

protected void closeZmq() {
    zmqClient.close();
    zmqContext.term();
}

protected abstract void requestInit();

public String getAddress() {
    return addressNoPort+servicePort;
}

public String getInitMessage() {
    return serviceId+":init";
}

}

how i run my application. 我如何运行我的应用程序。

public class TestServiceRunner {

public static void main(String[] args) {
    for (String string : args) {
        System.out.println("Params = "+string);
    }

    System.out.println("Starting Test service ...");

    TestService testService = new TestService(args);
    testService.run();
}

}

And my stacktrace 还有我的堆栈跟踪

Exception in thread "main" org.zeromq.ZMQException: No thread available(0x9523dfe)
    at org.zeromq.ZMQ$Socket.connect(Native Method)
    at GenericService.initZmq(GenericService.java:22)
    at TestService.run(TestService.java:25)
    at TestServiceRunner.main(TestServiceRunner.java:13)

Figured this one out! 想通了这个!

zmqContext = ZMQ.context(0); line in GenericService was the problem... The line should have been zmqContext = ZMQ.context(1); 问题是GenericService中的行...行应该是zmqContext = ZMQ.context(1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM