Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: changed "notify signal" to "notification"

...

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
bgColor#ccccff
public synchronized void doSomething(long timeout)
  throws InterruptedException {
 
  while (<condition does not hold>) {
    wait(timeout); // Immediately leaves current monitor
  }
}

...