From af2d692c5953f9cd1beee70a2aa9b2e45a7862b6 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Thu, 4 Oct 2012 06:13:19 +0200 Subject: [PATCH] Wait and notify on the correct lock. --- .../protocol/async/AsyncListenerHandler.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ProtocolLib/src/com/comphenix/protocol/async/AsyncListenerHandler.java b/ProtocolLib/src/com/comphenix/protocol/async/AsyncListenerHandler.java index 137327b8..8e729875 100644 --- a/ProtocolLib/src/com/comphenix/protocol/async/AsyncListenerHandler.java +++ b/ProtocolLib/src/com/comphenix/protocol/async/AsyncListenerHandler.java @@ -152,7 +152,7 @@ public class AsyncListenerHandler { synchronized (stopLock) { stoppedTasks.remove(id); - notifyAll(); + stopLock.notifyAll(); running.set(false); } @@ -269,10 +269,12 @@ public class AsyncListenerHandler { * @throws InterruptedException - If the current thread was interrupted. */ private boolean waitForStops() throws InterruptedException { - while (stoppedTasks.size() > 0 && !cancelled) { - wait(); + synchronized (stopLock) { + while (stoppedTasks.size() > 0 && !cancelled) { + stopLock.wait(); + } + return cancelled; } - return cancelled; } // DO NOT call this method from the main thread @@ -286,10 +288,8 @@ public class AsyncListenerHandler { try { // Wait if certain threads are stopping - synchronized (stopLock) { - if (waitForStops()) - return; - } + if (waitForStops()) + return; // Proceed started.incrementAndGet(); @@ -375,7 +375,7 @@ public class AsyncListenerHandler { // Individual shut down is irrelevant now synchronized (stopLock) { - notifyAll(); + stopLock.notifyAll(); } } }