Skip to content

Instantly share code, notes, and snippets.

@ivanursul
Created July 24, 2015 08:06
Show Gist options
  • Select an option

  • Save ivanursul/262d5794e557f3a0237f to your computer and use it in GitHub Desktop.

Select an option

Save ivanursul/262d5794e557f3a0237f to your computer and use it in GitHub Desktop.
public class MyWaitNotify{
String myMonitorObject = "";
boolean wasSignalled = false;
public void doWait(){
synchronized(myMonitorObject){
while(!wasSignalled){
try{
myMonitorObject.wait();
} catch(InterruptedException e){...}
}
//clear signal and continue running.
wasSignalled = false;
}
}
public void doNotify(){
synchronized(myMonitorObject){
wasSignalled = true;
myMonitorObject.notify();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment