aspose file tools*
The moose likes Threads and Synchronization and the fly likes why these methods Notify() , wait() and notifyall()  are in Object class?????? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "why these methods Notify() , wait() and notifyall()  are in Object class??????" Watch "why these methods Notify() , wait() and notifyall()  are in Object class??????" New topic
Author

why these methods Notify() , wait() and notifyall() are in Object class??????

ramakrishna rayudu
Ranch Hand

Joined: Mar 08, 2011
Posts: 57
hi..

i have a small doubt in my mind that why notify() , wait() and notifyall() methods are in Object class i think all these methods are related to the Threads right??
they should be some reason for that can you tell me wat is that reason??

Thanks,
Ramky
Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 418
    
    2

This question should probably be a sticky as we've answered it so many times .. if you search this forum you'll find several good answers and I recommend you do this.

The quick answer is they apply to a specific object instance i.e. if you didn't implement them on object you'd be left with implementing some static functions on say a class Threads that took a parameter of the object you wished to act on and then you'd have to be careful you passed the same object each time.



.. is that really better , I'd say not. I think every one would take the point that its not that intuitive to look for thread operations on object (had that feedback from many people) but once your past that initial 5 minutes of confusion (i.e. remembering to look at class object) it does work quite neatly and make sense ... honest ;-)


"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

ramakrishna rayudu, please SearchFirst. This question has been asked so many times, most recently less than two weeks ago: http://www.coderanch.com/t/535350/threads/java/Why-wait-notify-notifyAll-declared


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: why these methods Notify() , wait() and notifyall() are in Object class??????