Yes Sun there are. (Sun as in Sun LiWei, not as in Sun Microsystems...
).
Consider the following piece of code:
Imagine that the myMonitor object is not locked by any thread and a thread (let's call it T) attempts to execute the above piece of code. Since the monitor is unlocked, T is able to get hold of it (locks it) and starts executing the code within the synchronized block. As soon as T exits the synchronized block,
it releases the lock it holds on myMonitor; thereafter, myMonitor is free of locks and available for locking by another thread that can manage to get hold of it.
The difference this scenario has with an invocation of wait() is that a thread invoking wait() on a monitor, would result in the thread being added to the
wait set of the monitor, and a subsequent invocation of notify() would result in the thread moving back to a Ready state and competing for locking the object. (don't forget that wait() HAS to be invoked within a synchronized block). On the other hand, when a thread exits a synchronized block it (1) releases the lock and (2) gets out of the competition for the particular monitor altogether.
Hope this helps,
Panagiotis.
SCJP2, January 2001 (91%)
IBM Certified Solution Developer VAJ, May 2001
(After that I went on a "certification sabbatical" of sorts
)
[ September 12, 2002: Message edited by: Panagiotis Varlagas ]