File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes wait, notify and notifyAll Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "wait, notify and notifyAll" Watch "wait, notify and notifyAll" New topic

wait, notify and notifyAll

wrushasen dakhane
Ranch Hand

Joined: Sep 25, 2006
Posts: 47
Why the methods wait(), notify(), notifyAll() are in Object class and not in Thread class? Even though these methods are related to Threads.

SCJP 1.4, SCWCD 1.4
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Henry Wong

Joined: Sep 28, 2004
Posts: 20526

This exact question comes up every few months on this forum. Please search this forum for more discussions.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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.

Rahul Bhattacharjee
LinkedIn - Blog
I agree. Here's the link:
subject: wait, notify and notifyAll
It's not a secret anymore!