wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes Why wait and notify are methods of Object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Why wait and notify are methods of Object?" Watch "Why wait and notify are methods of Object?" New topic
Author

Why wait and notify are methods of Object?

vikasids sharma
Ranch Hand

Joined: Aug 01, 2003
Posts: 157
Why wait(), notify() and notifyAll() are methods of Object class and not Thread class when these methods are called for threads only?
Thanks,
Vikas


Thanks
Vikas Sharma
SCJP(1.4)
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
The methods are not only called on Threads.
The purpose of these methods is to provide a way to prevent an Object from being accessed from two different Threads at the same time. These methods allow Threads to have exclusive access to an object for the duration of an operation that should be considered atomic.
The reason they are in the Object class is because we must be able to make sure that any Object can be protected from concurrent access.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why wait and notify are methods of Object?
 
Similar Threads
Interview q
Object Class
wait, notify and notifyAll
Threads
wait() and notify() methods