Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

THREAD PRIORITY  RSS feed

 
Deepak Manchanda
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know that if notify() method is given to wake up multiple threads that are waiting, what is the procedure or order in which they are woken up? I mean, what if a user wants a particular thread of his choice to wake first so that he can work on it according to his need?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, notify() will only wake up one thread, not several. If there's more than one thread waiting (for the given monitor object), one will be picked at random and woken. You can't control which one this will be. If you want to wake more than one, use notifyAll(). But you can't control which one will be woken first.
If this level of control (or lack therof) is unacceptable, you probably need to use the Specific Notification pattern. Yopu can learn about this in the original paper by Tom Cargill or this later article by Peter Haggar.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!