Created
October 29, 2017 01:51
-
-
Save namchuai/9a6e1f031b0096bcf2cff3d0872a3f5e to your computer and use it in GitHub Desktop.
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 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