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