what wait() should be called from Synchrnoized block
posted 5 years ago
wait and join are two completely different things. join can only be called on a Thread object, but wait can be called on any object. To call wait on an object, you need to hold lock to that object. The idea behind it is that if some code has lock on an object (we don't want multiple threads to access this object simultaneously) and for some reason it can't use the object (lets say the code is waiting for user's input), then to allow other threads to use the object, the code will call wait on the object. That way it will release the lock on that object allowing other threads to use the object...
Stephan van Hulst