Created
July 24, 2015 08:06
-
-
Save ivanursul/262d5794e557f3a0237f 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 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