Created
October 29, 2017 01:47
-
-
Save namchuai/c3393ccbf7564528dbb0d16417c30c35 to your computer and use it in GitHub Desktop.
This file contains 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 MyWaitNotify3 { | |
MonitorObject myMonitorObject = new MonitorObject(); | |
boolean wasSignalled = false; | |
public void doWait() { | |
synchronized (myMonitorObject) { | |
while (!wasSignalled) { | |
try { | |
myMonitorObject.wait(); | |
} catch (InterruptedException e) { | |
} | |
} | |
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