What is the Diffrence Between Notify & NotifyAll" method in the Object Class ?
Ans:
'notifyAll()' it says that its will wake up all the threads waiting on the object and will select a thread to pass control to it
It is partly correct, notifyAll() will notify all the threads and after that all the threads will contest for the monitor lock. The thread that gets the monitor lock will start the work and the rest will be waiting for the monitor lock.
The above difference is pretty big as the threads waiting for monitor will not require a notify() call to start processing but will start processing as soon as they get the monitor lock.
If you take the thread dump and see the state of the threads (although getting this dump at the correct time is somewhat tough),
· In case of notify() only one thread will get to the RUNNING state and other will be in WAIT state
· In case of notifyAll() only one thread will get to the RUNNING state and other will be in BLOCKED state