cancel
Showing results for 
Search instead for 
Did you mean: 

Difference b/w notify and notifyall

Former Member
0 Kudos

Hi,

Can any body tell me

Whats the difference between notify() and notifyAll()?

Thank you,

Rajesh.N

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

notify() is used to unblock one waiting thread.

notifyAll() is used to unblock all of them.

notify() is preferable for performance when only one blocked thread can benefit from the change .

for example, when freeing a buffer back into a pool.And notifyAll() is necessary for correctness if multiple threads should resume .For example, when releasing a “writer” lock on a file might permit all “readers” to resume.

With regards,

Suman Sahu

Former Member
0 Kudos

Hi,

Check out the link

http://www.codecomments.com/archive245-2005-12-727949.html

notifyAll() wakes up ALL waiting threads; the scheduler decides which one will run.

notify() is used to unblock one waiting thread; notifyAll() is used to unblock all of them. Using notify() is preferable (for efficiency) when only one blocked thread can benefit from the change (for example, when freeing a buffer back into a pool). notifyAll() is necessary (for correctness) if multiple threads should resume (for example, when releasing a “writer” lock on a file might permit all “readers” to resume).

Regards,

Richa.<a href="http://www.codecomments.com/archive245-2005-12-727949.html">link</a>

Answers (0)