Last active
December 25, 2015 12:59
-
-
Save passichenko/6980170 to your computer and use it in GitHub Desktop.
corrected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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