File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt on Thread- wait()" Watch "Doubt on Thread- wait()" New topic
Author

Doubt on Thread- wait()

Saumya Srivastava
Ranch Hand

Joined: Mar 19, 2007
Posts: 45
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..?



OCPJP 6.0
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%
 
wood burning stoves
 
subject: Doubt on Thread- wait()
 
Similar Threads
Difference between notify and notifyAll
wait and notify help needed
Question On Object Locks.
wait and notify problem from K&B.
Multithreading: How can total be nearly 5,000 even though loop is up to 100?