gpt4 book ai didi

java - JZMQ错误: no thread available

转载 作者:太空宇宙 更新时间:2023-11-04 06:55:38 25 4
gpt4 key购买 nike

我正在尝试编写一个简单的java应用程序,它可以在服务器上运行并执行一些简单的操作。但目前我的应用程序因一个奇怪的错误而失败,我似乎找不到有关线程“main”org.zeromq.ZMQException中的异常:没有可用线程(0x9523dfe)

的任何信息

这两个服务在同一台服务器上运行,但只有我的应用程序失败。我只找到了关于 C zmq 框架的最少文档。对于 java 来说没有什么。

发生错误的类:

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)));
}

}

抽象通用服务类。

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";
}

}

我如何运行我的应用程序。

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();
}

}

还有我的堆栈跟踪

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)

最佳答案

解决了这个问题!

GenericService 中的

zmqContext = ZMQ.context(0); 行是问题所在...该行应该是 zmqContext = ZMQ.context(1);

关于java - JZMQ错误: no thread available,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22770503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com