| Author |
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.<br /> <br />#:^P
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
This exact question comes up every few months on this forum. Please search this forum for more discussions. Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
|
|
|
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
|
 |
 |
|
|
subject: wait, notify and notifyAll
|
|
|