BadriNath Ojha wrote:I wanted to know what happens when notify and notifyall is called on an object.
I read from some blog that when notify() is called only one thread out of many which called the wait() on the object is made awake from WAITING state and made RUNNABLE directly and when notifyall() is called then all the threads which called wait() are made awake but only one choosen by JVM scheduler and shifted to RUNNABLE state and others in BLOCKED state and not in WAITING state.
Please let me know.
Correct. Calling the notify() method will wake up one of the threads, that is waiting on the object, and put it in the block state (as it needs to reacquire the synchronization lock). Calling notifyAll() does that to all the threads waiting on the object.
Once a thread reacquires the synchronization lock, it becomes runnable, and can return from the wait() method.
Henry