The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: wait() and notify()

Reading articles is the first step, perhaps 10% of the process of learning. Us giving you more to read doesn't make that 10% any bigger. The other 80 - 90% is putting what you've read into practice, right and wrong, through coding. Show us what you've tried and ask any questions you have about the results.

Re: wait() and notify()

@chsvravikumar@gmail.com: Please check the most recent response date on threads. If a thread has been dormant for ~> 1 month, it's dead, the OP has moved on and probably doesn't care anymore.

However, if you have a gem of a good idea that you want to share with someone trying to do the same thing who may happen by someday, then by all means add it. (In this case, your post is not an example of such a gem.)

Re: wait() and notify()

Both the methods are used to block the thread for particular time interval until a specific condition is met. The necessity is that you need to ensure that any calls to wait() or notify() are within a synchronized area of code.
wait() : Causes current thread to release the lock and wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed.
notify() : Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation.