Skip to content

Instantly share code, notes, and snippets.

@namchuai
Created October 29, 2017 01:51
Show Gist options
  • Select an option

  • Save namchuai/9a6e1f031b0096bcf2cff3d0872a3f5e to your computer and use it in GitHub Desktop.

Select an option

Save namchuai/9a6e1f031b0096bcf2cff3d0872a3f5e 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 ex) {}
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