"Thread already started" error often occurs with openfire and asmack for IM functionality

Source: Internet
Author: User

Recent use of openfire and asmack to achieve the IM capabilities of Android, but the actual use of the process, often appear "Java.lang.IllegalThreadStateException:Thread already started" The error.

Like what:

Java.lang.IllegalThreadStateExceptionThread already startedjava.lang.Thread.checkNotStarted (thread.java:871) Java.lang.Thread.start (thread.java:1025) org.jivesoftware.smack.PacketWriter.startup (packetwriter.java:123) Org.jivesoftware.smack.XMPPConnection.initConnection (xmppconnection.java:684) Org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration (xmppconnection.java:645) Org.jivesoftware.smack.XMPPConnection.connect (xmppconnection.java:1062) Org.jivesoftware.smack.reconnectionmanager$2.run (reconnectionmanager.java:148)

Find out when Reconnectionmanager is re-connected, Packetreader and Packetwriter execute the Startup () method times wrong. The startup () method is primarily a thread that is used to parse packet.

"Thread already started", as the name implies, is the thread repeatedly started. I found for a long while did not find the reason, and finally found the reason in Connectionconfiguration.

Connectionconfiguration There is a parameter, reconnectionallowed, this parameter is actually whether to automatically connect. UseConnectionconfiguration.setreconnectionallowed (Boolean) to set whether to automatically connect,defaultRe try to connectIn casesuddenlydisconnected, reconnect management will immediately connect to the server and increase the delay when trying to connect failed. You can also manually connect by calling Connection.connect () yourself.

The problem is, I set mconnectionconfiguration.setreconnectionallowed (true), and at the same time I realized whether to drop the line, drop the line is connection.connect (). So it's tragic to repeat the operation.

The solution is also simple, either set not to connect automatically,setreconnectionallowed (false), or you do not have to implement the reconnection.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Thread already started" error often occurs with openfire and asmack for IM functionality

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.