aspose file tools*
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
Author

Dilemma about wait(timeout) and notify

Piter Tosic
Greenhorn

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???

Thanks.

Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 417
    
    2

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


"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: 281

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


http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dilemma about wait(timeout) and notify