File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wait, notify and notifyAll

 
wrushasen dakhane
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This exact question comes up every few months on this forum. Please search this forum for more discussions.

Henry
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic