Hi Kuldeep,
This is a simple case of a wait() and notifiy() methods to handle Threads. In addition we have the notifyAll() method.
All these 3 methods are relevant to synchronized methods. They can be called only from within a method which has been declared - synchronized.
When a wait() method is used, it is telling the
thread to vacate the synchronized lock(in other words - monitor) and go to sleep till any other thread enters the monitor and calls the notify() method.
When a notify() method is issued, as mentioned above, calls the first thread which had called wait() on a particular object.
Similarly, a notifyAll() wakes up all the threads sleeping due to calling the wait() method.
Hope it helps
Niraj