• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
ramakrishna rayudu
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ;-)

 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic