InterviewSolution
Saved Bookmarks
| 1. |
Why wait(), notify(), and notifyAll() methods are present in Object class? |
|
Answer» We know that every object has a monitor that allows the thread to HOLD a lock on the object. But the thread class doesn't contain any MONITORS. Thread usually waits for the object’s monitor (lock) by calling the wait() METHOD on an object, and notify other threads that are waiting for the same lock using notify() or notifyAll() method. Therefore, these three methods are CALLED on objects only and allow all threads to communicate with each that are CREATED on that object. |
|