File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt on Thread- wait() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt on Thread- wait()" Watch "Doubt on Thread- wait()" New topic

Doubt on Thread- wait()

Saumya Srivastava
Ranch Hand

Joined: Mar 19, 2007
Posts: 45

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

Joined: May 18, 2010
Posts: 634

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

OCPJP 6.0 93%
OCPJWCD 5.0 98%
I agree. Here's the link:
subject: Doubt on Thread- wait()
It's not a secret anymore!