Friday, August 11, 2017

Why wait() and notify(),nitifyAll() methods are in Object class not in thread class ?

In general, threads will work on locks. Every thread will aquire the lock first and start executing the tasks.

Threads itself don't have locks. So in Java Object class is the super class for all the classes. These methods should be available for all the classes.

That is why wait(),notify() and notifyAll() methods are provided in Object class.

No comments: