...
This compliant solution defines the doSomething()
method with a timeout
parameter instead of the time
value. The use of the Object.wait()
method instead of Thread.sleep()
allows setting a time out for a period during which a notify signal notification may awaken the thread.
Code Block | ||
---|---|---|
| ||
public synchronized void doSomething(long timeout) throws InterruptedException { while (<condition does not hold>) { wait(timeout); // Immediately leaves current monitor } } |
...