| 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
|
 |
 |
|
|
subject: wait() notify() notifyAll() ???
|
|
|