Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on Thread- wait()

 
Saumya Srivastava
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was running the code below and thought of commenting the line calling notify(). So that I may see if I get IIlegalMonitorStateException. But the code ran successfully without throwing error. Please explain me why? Isn't it necessary for the thread to send notify() to the waiting thread? I think main() thread should throw the exception after not receiving notification from ThreadB b? Please correct me ...if my understanding is wrong..?

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's not necessary to call notify

It's simply to notify waiting thread to wake up.
if not implemeted,the waiting thread would not wake up
that's it..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic