mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-30 14:43:27 +01:00
Wait and notify on the correct lock.
This commit is contained in:
parent
db8db1fba1
commit
af2d692c59
@ -152,7 +152,7 @@ public class AsyncListenerHandler {
|
|||||||
|
|
||||||
synchronized (stopLock) {
|
synchronized (stopLock) {
|
||||||
stoppedTasks.remove(id);
|
stoppedTasks.remove(id);
|
||||||
notifyAll();
|
stopLock.notifyAll();
|
||||||
running.set(false);
|
running.set(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,11 +269,13 @@ public class AsyncListenerHandler {
|
|||||||
* @throws InterruptedException - If the current thread was interrupted.
|
* @throws InterruptedException - If the current thread was interrupted.
|
||||||
*/
|
*/
|
||||||
private boolean waitForStops() throws InterruptedException {
|
private boolean waitForStops() throws InterruptedException {
|
||||||
|
synchronized (stopLock) {
|
||||||
while (stoppedTasks.size() > 0 && !cancelled) {
|
while (stoppedTasks.size() > 0 && !cancelled) {
|
||||||
wait();
|
stopLock.wait();
|
||||||
}
|
}
|
||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DO NOT call this method from the main thread
|
// DO NOT call this method from the main thread
|
||||||
private void listenerLoop(int workerID) {
|
private void listenerLoop(int workerID) {
|
||||||
@ -286,10 +288,8 @@ public class AsyncListenerHandler {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Wait if certain threads are stopping
|
// Wait if certain threads are stopping
|
||||||
synchronized (stopLock) {
|
|
||||||
if (waitForStops())
|
if (waitForStops())
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Proceed
|
// Proceed
|
||||||
started.incrementAndGet();
|
started.incrementAndGet();
|
||||||
@ -375,7 +375,7 @@ public class AsyncListenerHandler {
|
|||||||
|
|
||||||
// Individual shut down is irrelevant now
|
// Individual shut down is irrelevant now
|
||||||
synchronized (stopLock) {
|
synchronized (stopLock) {
|
||||||
notifyAll();
|
stopLock.notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user