Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt on Thread- wait()  RSS feed

 
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..
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!