...
Because the method is synchronized, if the thread is suspended, other threads are unable to use the synchronized methods of the class. The current object's monitor is not released because the Thread.sleep()
method does not have any synchronization semantics, as detailed in guideline THI00-J. Do not assume that the sleep(), yield() or getState() methods provide synchronization semantics.
Compliant Solution (
...
Intrinsic Lock)
This compliant solution defines the doSomething()
method with a timeout
parameter instead of the time
value. Using Object.wait()
instead of Thread.sleep()
allows setting a time out period during which a notification may awaken the thread.
...