• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dilemma about wait(timeout) and notify

 
Piter Tosic
Greenhorn
Posts: 2
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you notify it wakes up before the timeout but note it can wake up spuriously also read this ..
wait
 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic