diff --git a/source/org/jivesoftware/smack/PacketReader.java b/source/org/jivesoftware/smack/PacketReader.java index 25c5c0427..1a6fbdd8f 100644 --- a/source/org/jivesoftware/smack/PacketReader.java +++ b/source/org/jivesoftware/smack/PacketReader.java @@ -77,7 +77,7 @@ class PacketReader { parsePackets(this); } }; - readerThread.setName("Smack Packet Reader"); + readerThread.setName("Smack Packet Reader (" + connection.connectionCounterValue + ")"); readerThread.setDaemon(true); listenerThread = new Thread() { @@ -90,7 +90,7 @@ class PacketReader { } } }; - listenerThread.setName("Smack Listener Processor"); + listenerThread.setName("Smack Listener Processor (" + connection.connectionCounterValue + ")"); listenerThread.setDaemon(true); resetParser(); diff --git a/source/org/jivesoftware/smack/PacketWriter.java b/source/org/jivesoftware/smack/PacketWriter.java index 0019454bd..bffbee6aa 100644 --- a/source/org/jivesoftware/smack/PacketWriter.java +++ b/source/org/jivesoftware/smack/PacketWriter.java @@ -92,7 +92,7 @@ class PacketWriter { writePackets(this); } }; - writerThread.setName("Smack Packet Writer"); + writerThread.setName("Smack Packet Writer (" + connection.connectionCounterValue + ")"); writerThread.setDaemon(true); } @@ -222,7 +222,7 @@ class PacketWriter { keepAliveThread = new Thread(target); target.setThread(keepAliveThread); keepAliveThread.setDaemon(true); - keepAliveThread.setName("Smack Keep Alive"); + keepAliveThread.setName("Smack Keep Alive (" + connection.connectionCounterValue + ")"); keepAliveThread.start(); } } diff --git a/source/org/jivesoftware/smack/XMPPConnection.java b/source/org/jivesoftware/smack/XMPPConnection.java index 6390f1683..10f567f21 100644 --- a/source/org/jivesoftware/smack/XMPPConnection.java +++ b/source/org/jivesoftware/smack/XMPPConnection.java @@ -37,6 +37,7 @@ import java.net.UnknownHostException; import java.util.Collection; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.atomic.AtomicInteger; /** * Creates a connection to a XMPP server. A simple use of this API might @@ -91,6 +92,10 @@ public class XMPPConnection { private final static Set connectionEstablishedListeners = new CopyOnWriteArraySet(); + // Counter to uniquely identify connections that are created. This is distinct from the + // connection ID, which is a value sent by the server once a connection is made. + private static AtomicInteger connectionCounter = new AtomicInteger(0); + static { // Use try block since we may not have permission to get a system // property (for example, when an applet). @@ -121,6 +126,7 @@ public class XMPPConnection { */ String serviceName; + int connectionCounterValue = connectionCounter.getAndIncrement(); String connectionID = null; private String user = null; private boolean connected = false;