• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

wait, notify and notifyAll

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why the methods wait(), notify(), notifyAll() are in Object class and not in Thread class? Even though these methods are related to Threads.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the point of view of completing a project, there's not a great deal to be gained by asking why things are how they are in the Java API and wishing they were different. Most things in Java are how they are for good reasons. Some things are not as good as they could be (clone, calendars etc.), but cannot change now because of the need for backwards-compatibility.

For interest, the Java designers probably decided to make these instance methods on an Object, because they act on the monitor of a specific instance of Object. That means that they can have the simplest possible signature: no arguments at all. They could have been made methods on Thread, but then you'd have had to pass in the Object whose monitor was to be used; also, no data or methods of Thread would be used, so the methods would not sit comfortably in Thread. They could even have decided to have separate Monitor objects, rather than putting the functionality in Object.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This exact question comes up every few months on this forum. Please search this forum for more discussions.

Henry
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that wait , notify , notifyall are lock/mutex related methods.As all objects have lock ,so these methods have been kept on java.lang.Object class ,not in Thread class.
 
reply
    Bookmark Topic Watch Topic
  • New Topic