Why are the methods wait() and notify() defined in the Object class when they are used with Threads?

Rob Edmondson

The wait() and notify() methods are object-specific. The wait() method suspends the current thread of execution, and tells the object to keep track of the suspended thread. The notify() method tells the object to wake up the suspended threads that it is currently keeping track of. Since wait() and notify() are object specific, they must be used within code that is synchronized on the object in question.

It is also important to use state variables when using wait() and notify(), as threads can be woken up by conditions other than notify().

suspend() is similar to wait() but does not add the thread to an object's wait list.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact