Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » MQTT connection threads are getting hanged.(MQTT connections threads are getting hanged.)
MQTT connection threads are getting hanged. [message #1221841] Wed, 18 December 2013 14:29 Go to next message
uday kumar is currently offline uday kumarFriend
Messages: 3
Registered: December 2013
Junior Member


Hi,

I am not sue is this the right forum to post mqtt issue if not please advise the right forum to post.

I am using paho mqtt java client for publishing, i am facing the issue with the number of threads getting increased, for each connection there are three threads are getting created with snd,call and rec at some point of time threads are getting exhausted and other threads getting hanged.
I am trying to reuse the connect, but the connection gets disconnected and it creates new connection with new client id at the time of publish by this threads are getting increased and the old threads which are created with previous connection are not getting cleared. We are using only for publish with clean session true and with no call back.

And also the tmp folder is getting full with this new connections even after not setting the persistence while connection

What is the best way to create the connection and reusing the connections instead of creating new connection on every publish. Is it advisable to create new connection and disconnect on every publish.

Here is the track trace from thread dump:
java.lang.Thread.State: WAITING
at java.lang.Object.wait(Native Method)
- waiting on <53000ae6> (a java.lang.Object)
at java.lang.Object.wait(Object.java:503)
at org.eclipse.paho.client.mqttv3.internal.Token.waitForResponse(Token.java:122)
at org.eclipse.paho.client.mqttv3.internal.Token.waitForCompletion(Token.java:90)
at org.eclipse.paho.client.mqttv3.MqttToken.waitForCompletion(MqttToken.java:50)
at org.eclipse.paho.client.mqttv3.MqttClient.publish(MqttClient.java:272)
Re: MQTT connection threads are getting hanged. [message #1221887 is a reply to message #1221841] Wed, 18 December 2013 16:12 Go to previous messageGo to next message
Ian Craggs is currently offline Ian CraggsFriend
Messages: 83
Registered: March 2013
Member
Hi,

this is as good a place as any. You don't need to create a new connection for each publish. Your program should look something like:

client = MqttClient(serverURI, clientId); // create a new client

client.connect();

client.publish(topic, message); // as many times as you like

client.disconnect();


Ian Craggs
Re: MQTT connection threads are getting hanged. [message #1221906 is a reply to message #1221887] Wed, 18 December 2013 17:03 Go to previous messageGo to next message
uday kumar is currently offline uday kumarFriend
Messages: 3
Registered: December 2013
Junior Member
Hi Ian,

Thanks for the Reply.

I have few queries.

Why the threads are not cleared when the connection gets disconnect, i see threads getting increased and causing the thread blocking.
Why the folders are getting created with client id names, when persistence is not used. If this is the case tmp folder gets full,
Is it must to provide unique clientid when new connection is established.
Is there any way to have connection pool kind of thing like cacheconnection pool, to avoid creating connections every time instead reuse from pool.

What is the best way to create connections for publishing,

What does below exception mean from thread dump:
java.lang.Thread.State: WAITING
at java.lang.Object.wait(Native Method)
- waiting on <53000ae6> (a java.lang.Object)
at java.lang.Object.wait(Object.java:503)
at org.eclipse.paho.client.mqttv3.internal.Token.waitForResponse(Token.java:122)
at org.eclipse.paho.client.mqttv3.internal.Token.waitForCompletion(Token.java:90)
at org.eclipse.paho.client.mqttv3.MqttToken.waitForCompletion(MqttToken.java:50)
at org.eclipse.paho.client.mqttv3.MqttClient.publish(MqttClient.java:272)

Here is the code i am using Please suggest best ways to avoid thread blocking and best way to create connection. publish method is called with through put of more than 100 messages per second.

private MqttClient client; //class variable

public MqttClient getNewConnection(String clientId) {


try {
logger.info("Broker Url "+brokerUrl +" clientId "+clientId +" "+tmpDir);
client = new MqttClient(this.brokerUrl, clientId);

// Set this wrapper as the callback handler
client.setCallback(this);
} catch (MqttException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return client;
}

// before every publish check for isConnected if not create new connection and with new clientId.
if(client == null || !client.isConnected())
{
client = getNewConnection(Constants.MQTT_PREFIX + RandomStringUtils.randomAlphanumeric(Constants.MQTT_CLIENT_ID_LEN));
client.connect(conOpt);
}

[Updated on: Thu, 19 December 2013 07:52]

Report message to a moderator

Re: MQTT connection threads are getting hanged. [message #1222287 is a reply to message #1221906] Fri, 20 December 2013 04:01 Go to previous messageGo to next message
uday kumar is currently offline uday kumarFriend
Messages: 3
Registered: December 2013
Junior Member
Any suggestions please, i am blocked with mqtt client send consuming more CPU than my application.
Re: MQTT connection threads are getting hanged. [message #1264825 is a reply to message #1222287] Wed, 05 March 2014 14:34 Go to previous message
Ian Craggs is currently offline Ian CraggsFriend
Messages: 83
Registered: March 2013
Member
Sorry, I seem to have missed your question.

I will answer one point. Your call to

client = new MqttClient(this.brokerUrl, clientId);

means persistence is on - it's the default. If you want to turn persistence off, then you need to call

client = new MqttClient(this.brokerUrl, clientId, null);

Ian
Previous Topic:How to install Paho ?
Next Topic:Paho Java Client under JBoss
Goto Forum:
  


Current Time: Thu Apr 25 09:39:56 GMT 2024

Powered by FUDForum. Page generated in 0.03389 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top