aspose file tools
The moose likes Threads and Synchronization and the fly likes wait() notify() notifyAll() ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "wait() notify() notifyAll() ???" Watch "wait() notify() notifyAll() ???" New topic
Author

wait() notify() notifyAll() ???

Amitkumar Dhama
Ranch Hand

Joined: Feb 14, 2005
Posts: 56
Hi all,

can anybody tell me,

1.Why wait() notify() and notifyAll() are declared in the Object class instead of Thread class.

Thanking in advance....


SCJP 1.4, SCWCD 1.4, M.Tech(CSE)
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
Hi.

The reason that these functions are in the Object class is because you want to be able to lock on any object and not only on Thread objects.
For example, let's say i want to lock on a specific Class I created named Lock. Then i can use this code below even though Lock doesn't inherit from Thread (it is just a refular Class in java).



as you can see, we can lock on that object and go to "sleep" (wait) on it anytime we want...

Hope it helped a bit.

Roy
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: wait() notify() notifyAll() ???
 
Similar Threads
Interview q
Threads
thread question
Regarding Thread class
Object Class