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
Joined: Jan 13, 2002
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...