Example & Tutorial understanding programming in easy ways.

Why wait, notify and notifyAll are not inside thread class?

In order to answer this question, you have to give some reasons
why it make sense for these three method to be in Object class, and why not on
Thread class.

One reason which is obvious is that Java provides lock at object level
not at thread level. Every object has lock, which is acquired by thread.

Now if thread needs to wait for certain lock it make sense to call wait() on that object rather than
on that thread. Had wait() method declared on Thread class, it was not clear that
for which lock thread was waiting. In short, since wait, notify and notifyAll operate at lock level, it make sense to defined it on object class because lock belongs to object.

Read More →