• Post Reply Bookmark Topic Watch Topic
  • New Topic

Notify vs Notify All  RSS feed

 
nitinram agarwal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
in multi threading application we have the choice of using either notify or notifyAll. Now in any case only one thread will be running amongst a number of waiting thread when the thread on which these waiting threads are waiting. What if the thread on which all other threads are waiting, calls notify instead of notifyAll.
1. Is calling notify means that only one amongst the waiting thread will be randomly selected and executed and all other waiting threads will keep waiting?
2. In case notifyAll is called then all the waiting threads will get chance to acquire the lock and will be executed in some sequence?

Regards,
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nitinram agarwal wrote:Hi,
in multi threading application we have the choice of using either notify or notifyAll. Now in any case only one thread will be running amongst a number of waiting thread when the thread on which these waiting threads are waiting. What if the thread on which all other threads are waiting, calls notify instead of notifyAll.
1. Is calling notify means that only one amongst the waiting thread will be randomly selected and executed and all other waiting threads will keep waiting?


Yes. Which is exactly what the docs say.

2. In case notifyAll is called then all the waiting threads will get chance to acquire the lock and will be executed in some sequence?


Yes. Which is what the docs say.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!