Menu Bar

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, 4 December 2016

What is the difference between notify() and notifyAll() methods in Java ?



Difference between notify() and notifyAll() methods in Java ?

In Java there are two methods i.e notify() and notifyAll() which are used to wake up threads from the waiting state. These methods along with wait() method are used to establish a communication between the threads.

A thread goes in a WAITING state by calling wait() method, now the waiting thread will always be in waiting state until any other thread call notify() and notifyAll() method.

notify() :
When a thread calls notify() method, only one thread will be notified which is waiting for the lock.notify() does not guarantee that it will starts the first waiting thread ,so Thread-scheduler pick a random thread from a pool of waiting thread ,here Thread-scheduler guarantee that it will pick only one thread .

notifyAll() :
When a thread calls notifyAll() method, all threads are notified which are in waiting for the lock.And all threads will move from the WAITING state to BLOCKED state ,and threads will get a lock on the basis of their priority. And the thread which get a lock will move from BLOCKED state to RUNNING state.



      
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



Share this Blog with yours Friends !!

No comments:

Post a Comment