• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 443
3
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ;-)

 
Sheriff
Posts: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ramakrishna rayudu, please SearchFirst. This question has been asked so many times, most recently less than two weeks ago: https://coderanch.com/t/535350/threads/java/Why-wait-notify-notifyAll-declared
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic