Javaで.NETのManualResetEventクラスと同等なものを作成
What is java's equivalent of ManualResetEvent?
http://stackoverflow.com/questions/1064596/what-is-javas-equivalent-of-manualresetevent
/**
* original: http://stackoverflow.com/questions/1064596/what-is-javas-equivalent-of-manualresetevent
*/
class ManualResetEvent {
private final Object monitor = new Object();
private volatile boolean open = false;
public ManualResetEvent(boolean open) {
this.open = open;
}
public void waitOne() throws InterruptedException {
synchronized (monitor) {
while (open==false) {
monitor.wait();
}
}
}
public boolean waitOne(long milliseconds) throws InterruptedException {
synchronized (monitor) {
if (open)
return true;
monitor.wait(milliseconds);
return open;
}
}
public void set() {//open start
synchronized (monitor) {
open = true;
monitor.notifyAll();
}
}
public void reset() {//close stop
open = false;
}
}