Hello Sudha,
The concept is this way:
Every object in
java can act as what we call a monitor. A monitor is basically an object that has some sychronised code. It is a shared resource we can say.
Every monitor, has a lock associated with it. If a thread wants to excute the synchronised code of the monitor, it needs to get the lock on the monitor.Once a thread locks a monitor, no other thread can access it.
Now, when a thread gains control over a monitor and excutes
wait(), then the current thread gives up the lock on the monitor and goes into a pool of waiting thread.(Threads waitig to acquire lock on the monitor).The monitor is now available to any other thread that is seeking the monitor.
Now when some other thread excutes the notify() or notifyAll()method inside the monitor, then one or more of the threads from the waiting pool for that monitor will move into a seeking Lock state for the monitor. The thread that acquires the lock can excute the monitor.
One advantage of this approach is that a thread need not have to check the state of the monitor(ie lock or unlock)on its own. Its will be notified by the java system.
Hope my explanation helps.