Saturday, April 17, 2010

Have you ever wondered the difference between notify and notifyAll?

Have you ever wondered difference between notify and notifyAll methods in object?

Notify notifies only one thread that is waiting on the object. NotifyAll notifies all the threads that are waiting on the object.

Now what happens when more than one thread is waiting on the same object and notify is invoked?

Only one of these waiting thread will be entering into running state and all the other threads will be in waiting state. On the other hand, in you invoke notifyAll, all the threads will be entering into running state one by one.

No comments:

Post a Comment