Why the above three methods in Object class instead of Thread class?

Methods wait() and notify(), remember, are instance methods of Object.
In the same way that every object has a lock, every object can have a list of threads
that are waiting for a signal (a notification) from the object. A thread gets on
this waiting list by executing the wait() method of the target object. From that
moment, it doesn't execute any further instructions until the notify() method of
the target object is called. If many threads are waiting on the same object, only one
will be chosen (in no guaranteed order) to proceed with its execution. If there are
no threads waiting, then no particular action is taken.

No comments:

Post a Comment