From 57a5f88ead090d0c6c436c411e3b030d15d15e95 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 22 Mar 2013 18:14:08 +0000 Subject: [PATCH] SMACK-384 Don't use a semaphore while waiting for PacketReader to be started. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_3_0@13577 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smack/PacketReader.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/source/org/jivesoftware/smack/PacketReader.java b/source/org/jivesoftware/smack/PacketReader.java index af1c7682f..826360cf3 100644 --- a/source/org/jivesoftware/smack/PacketReader.java +++ b/source/org/jivesoftware/smack/PacketReader.java @@ -51,7 +51,6 @@ class PacketReader { volatile boolean done; private String connectionID = null; - private Semaphore connectionSemaphore; protected PacketReader(final XMPPConnection connection) { this.connection = connection; @@ -97,21 +96,17 @@ class PacketReader { * @throws XMPPException if the server fails to send an opening stream back * for more than five seconds. */ - public void startup() throws XMPPException { - connectionSemaphore = new Semaphore(1); - + synchronized public void startup() throws XMPPException { readerThread.start(); - // Wait for stream tag before returing. We'll wait a couple of seconds before + // Wait for stream tag before returning. We'll wait a couple of seconds before // giving up and throwing an error. try { - connectionSemaphore.acquire(); - // A waiting thread may be woken up before the wait time or a notify // (although this is a rare thing). Therefore, we continue waiting // until either a connectionID has been set (and hence a notify was // made) or the total wait time has elapsed. int waitTime = SmackConfiguration.getPacketReplyTimeout(); - connectionSemaphore.tryAcquire(3 * waitTime, TimeUnit.MILLISECONDS); + wait(3 * waitTime); } catch (InterruptedException ie) { // Ignore. @@ -304,8 +299,8 @@ class PacketReader { * 3) TLS negotiation was successful * */ - private void releaseConnectionIDLock() { - connectionSemaphore.release(); + synchronized private void releaseConnectionIDLock() { + notify(); } /**