These two links provide the most comprehensive explaination for this question:
http://geekexplains.blogspot.com/2009/10/why-waitnotify-and-notifyall-in-object.html
http://javaqna.wordpress.com/2008/07/07/why-wait-and-notify-methods-are-in-object-class-not-in-thread/
X-----X
Below are some snippets from the above links:-
1. Java concurrency model uses locks to implement mutually exclusive access to objects in a multi-threaded environment and locks are associated with every object in Java not only with threads.
2. wait, notify/notifyAll methods are used by threads to communicate with each other while trying to access a common object. Putting it differently, objects become a medium via which threads communicate with each other.
3. Evidently you see that these three methods are essentially object-related and not thread-related and hence the designers of Java language considered it wise to put them in Object class instead of putting them in Thread class.
4. The usage of the 'object' is the particular object's prerogative and not that of the required threads. Putting these three methods in the Object class helps the objects owning/controlling their usage in a better way ...
5. the communication among the interested threads becomes far too easier when the control is kept at the object's level - one common shared resource/medium and all interested threads communicating via it.
http://geekexplains.blogspot.com/2009/10/why-waitnotify-and-notifyall-in-object.html
http://javaqna.wordpress.com/2008/07/07/why-wait-and-notify-methods-are-in-object-class-not-in-thread/
X-----X
Below are some snippets from the above links:-
1. Java concurrency model uses locks to implement mutually exclusive access to objects in a multi-threaded environment and locks are associated with every object in Java not only with threads.
2. wait, notify/notifyAll methods are used by threads to communicate with each other while trying to access a common object. Putting it differently, objects become a medium via which threads communicate with each other.
3. Evidently you see that these three methods are essentially object-related and not thread-related and hence the designers of Java language considered it wise to put them in Object class instead of putting them in Thread class.
4. The usage of the 'object' is the particular object's prerogative and not that of the required threads. Putting these three methods in the Object class helps the objects owning/controlling their usage in a better way ...
5. the communication among the interested threads becomes far too easier when the control is kept at the object's level - one common shared resource/medium and all interested threads communicating via it.
No comments:
Post a Comment