EpicAnchors/EpicAnchors-Plugin/src/main/java/com/songoda/epicanchors/utils/ThreadSync.java

31 lines
746 B
Java

package com.songoda.epicanchors.utils;
import java.util.concurrent.atomic.AtomicReference;
public class ThreadSync {
private final Object syncObj = new Object();
private final AtomicReference<Boolean> waiting = new AtomicReference<>(true);
public void waitForRelease() {
synchronized (this.syncObj) {
while (this.waiting.get()) {
try {
this.syncObj.wait();
} catch (Exception ignore) {
}
}
}
}
public void release() {
synchronized (this.syncObj) {
this.waiting.set(false);
this.syncObj.notifyAll();
}
}
public void reset() {
this.waiting.set(true);
}
}