jQuery in Action, 3rd edition
The moose likes Threads and Synchronization and the fly likes Dilemma about wait(timeout) and notify Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Dilemma about wait(timeout) and notify" Watch "Dilemma about wait(timeout) and notify" New topic

Dilemma about wait(timeout) and notify

Piter Tosic

Joined: Aug 01, 2011
Posts: 2

what happens if I have thread which waits on
for example and someone calls notifyAll() from another synch method.

Do thread continue waiting till the time is lapse then is woke up or notifyAll() wakes them up regardlessly of time which is not yet elapsed???


Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 443

If you notify it wakes up before the timeout but note it can wake up spuriously also read this ..

"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 295

timeout will only come in picture if notify() or notifyAll() is not called otherwise Thread can woke up even before timeout.

Its also worth noting that :

1) Wait should always be called from synchronized context
2) Wait should always be called from inside loop

SQL Query Interview Question java67 Javarevisited
I agree. Here's the link: http://aspose.com/file-tools
subject: Dilemma about wait(timeout) and notify
It's not a secret anymore!