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 About Wait() and notify() method 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 "About Wait() and notify() method" Watch "About Wait() and notify() method" New topic

About Wait() and notify() method

Sanjeev Narula

Joined: Mar 16, 2007
Posts: 19
Can anyone explain about wait() and notify() method giving some example.

Thanks in advance.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1710
Hi Sanjeev,

See the code below:

Try to run this, with Line1 and Line 2 and without Line 1 and Line 2.
Without Line 1 - Line 2, the output is indeterministic but with wait(), the output is surely "sum = 55".
with wait, main waits for thread ww to notify it before it could print the

See the book for more detail!


m ali
Ranch Hand

Joined: Apr 12, 2007
Posts: 49
Hi Chandra,

Thanks for the nice example.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
Here is another example.

You can see the applet in action at
I agree. Here's the link:
subject: About Wait() and notify() method
It's not a secret anymore!