Originally posted by Aaron Anders: does the internal implementation of synchronized method/statement make use of wait()/notify()/notifyall()?
No. To the contrary, wait/notify are built upon the synchronized statement in the sense that you must own a monitor lock (i.e. be inside a synchronized method or block) before you can call wait() or notify() on an object. Synchronization is a way to ensure that some operations are atomic w.r.t. other threads, in other words, that only one thread can execute the synchronized method(s) or block(s) at any given time. Inside a synchronized method/block, the thread is the exclusive owner of the object's monitor lock. The wait/notify methods, on the other hand, are a way to co-ordinate actions between different threads. They allow a thread to release its monitor lock and wait() for something to happen, or to notify() waiting threads that something happened. - Peter
Joined: Dec 30, 2002
thanks for the reply. i have one more question while reading JDK doc, it says "wait() ... The current thread must own this object's monitor.", what will happen if i wait for object other than i've been synchronized for? i.e.