Editorial / Best Answer
janswain
Each object in java is associated with a lock and the wait and notify methods are not associated with a thread but with a lock, so coupling locks and objects meant that each object should have wait and notify methods that operate on that object’s lock.
Java provides a way to lock the code for a thread which is currently executing it using the synchorinized keyword, and making other threads that wish to use it wait until the first thread is finished.These other threads are placed in the waiting state .Once the first thread completes it task than it notifies others in the queue by giving the lock to JVM.Now JVM decides which thread will exceute next by its internal algo.Hence, the wait and notify methods has to be in Object class as it acquires lock and has to notify others.....
Wait(), notify() and notyfyAll() methods
Profile Answers by varalakshmi.k Questions by varalakshmi.k
Questions by varalakshmi.k
Editorial / Best Answer
janswainProfile Answers by janswain Questions by janswain
Each object in java is associated with a lock and the wait and notify methods are not associated with a thread but with a lock, so coupling locks and objects meant that each object should have wait and notify methods that operate on that object’s lock.
Java provides a way to lock the code for a thread which is currently executing it using the synchorinized keyword, and making other threads that wish to use it wait until the first thread is finished.These other threads are placed in the waiting state .Once the first thread completes it task than it notifies others in the queue by giving the lock to JVM.Now JVM decides which thread will exceute next by its internal algo.Hence, the wait and notify methods has to be in Object class as it acquires lock and has to notify others.....
Related Answered Questions
Related Open Questions