From bf02dbe3daa0e5467c756fcb08b36f51cdff992d Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Sun, 4 Feb 2007 20:52:45 +0000 Subject: [PATCH] Added unique identifier to each thread name (SMACK-51). git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@6948 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smack/PacketReader.java | 4 ++-- source/org/jivesoftware/smack/PacketWriter.java | 4 ++-- source/org/jivesoftware/smack/XMPPConnection.java | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) 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;