当我运行Eclipse并编译我的程序时,它只运行一次,并且在第一次执行程序后,如果我再次尝试运行它,我会收到:
Exception in thread "main" Persistence is already in use
要解决这个问题,我必须关闭Eclipse并重新打开它,每次都会发生同样的事情,否则我可以运行我的程序,收到发布的消息。
该错误意味着什么,我该如何解决?
更新
client != null
Client is Connected
synchCB->@onSuccess(): Connection Successfull
Client is CONNECTED and Resources will be released.
AsynchCB->@deliveryComplete():
MSG: .00088782
Exception in thread "main" Verbindung zu Client ist hergestellt (32100)
at
org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31)
at org.eclipse.paho.client.mqttv3.internal.ClientComms.close(ClientComms.java:166)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.close(MqttAsyncClient.java:873)
at org.eclipse.paho.client.mqttv3.MqttClient.close(MqttClient.java:401)
at com.example.mqtt_java.MainClass.releaseResources(MainClass.java:87)
at com.example.mqtt_java.MainClass.main(MainClass.java:53)
代码:
client = new MqttClient(serverURI, clientID);
//client = MQTTClientFactory.newClient(IP, PORT, clientID);
if (client != null) {
System.out.println("client is not null");
//client.setCallback(AsynchCB);
//IMqttToken token = client.connectWithResult(opts);
client.connect();
if (client.isConnected()) {
System.out.println("Client is Connected");
client.publish(TOPIC, "33300".getBytes(), QoS, false);
client.close();
client.disconnect();
}else {
System.out.println("client is not connected");
}
}else {
System.out.println("client = null");
}
}
Console_output :
Exception in thread "main" Persistenz wird bereits verwendet (32200)
at
rg.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.open(MqttDefaultFilePersistence.java:112)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:286)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:167)
at org.eclipse.paho.client.mqttv3.MqttClient.<init>(MqttClient.java:224)
at org.eclipse.paho.client.mqttv3.MqttClient.<init>(MqttClient.java:136)
at com.example.mqtt_java.MainClass.main(MainClass.java:47)
答案 0 :(得分:1)
检查您是否确实关闭了该程序的原始版本(单击控制台中的红叉)。
您可能有一些后台(MQTT)线程没有关闭,因此保持应用程序运行并持有锁定在持久性目录上。