[Java - Synchronization] Wait() and Notify()
1) Explanation wait() tells the calling thread to wait (possibly forever) until some other thread tells it to resume using the method, notify( ). notify method is used, with wait(), to wake up threads that are waiting for an access to this object’s monitor. There are two ways to notify; notify() and notifyAll(). Notify() will wake up a randomly selected thread waiting on this object’s monitor. Since notify() wakes up a single random thread it can be used to implement mutually exclusive locking where threads are doing similar tasks, but in most cases, it would be more viable to implement notifyAll(). NotifyAll() wakes all threads that are waiting on this object’s monitor. The awakened threads will complete in the usual manner – like any other thread. * There is a tricky part about notify methods, and that is, it only releases the lock after the methods following the notify method is completed as well (usually until it reaches the wait() statemen...