• Post Reply Bookmark Topic Watch Topic
  • New Topic

multiple waiting threads. only one notified  RSS feed

 
duck worth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Easy-peasy one for somebody. You have multiple threads calling waiting for another thread. But that thread only calls notify(). Hence only tells one of the waiting threads the lock is going to become available. What happens to the other poor threads. Do they wait forever more???

Duck out
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They'll wait until notify is called again. Or notifyAll is called.
 
duck worth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so basically, if the thread never calls it again they're stuck. Suppose that leaves it down to sensible code design

many thanks
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, they are stuck.

But the wait method is overloaded to take a long value that specifies the time limit in milliseconds. if this is exceeded, it simply carries on.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!