Skip to content

Instantly share code, notes, and snippets.

@passichenko
Last active December 25, 2015 12:59
Show Gist options
  • Select an option

  • Save passichenko/6980170 to your computer and use it in GitHub Desktop.

Select an option

Save passichenko/6980170 to your computer and use it in GitHub Desktop.
corrected
public class Sample {
private volatile boolean ready = false;
private final Object lock = new Object();
public void m1() throws InterruptedException {
synchronized(lock) {
new Thread(new Runnable() {
public void run() {
m2();
}
}).start();
while(!ready) lock.wait();
}
}
public void m2() {
synchronized (lock){
// some operations
ready = true;
}
}
public static void main(String[] args) throws InterruptedException {
new Sample().m1();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment