Why are wait, notify, notifyAll defined in Object?

This is a design-related issue, which examines the interviewer's views on existing systems and things that are ubiquitous but seem unreasonable. When answering these questions, you have to explain why it makes sense to put these methods in the Object class, and why not put them in the Thread class. An obvious reason is that the locks provided by JAVA are at the object level rather than the thread level. Each object has a lock, which is acquired by the thread. If the thread needs to wait for some lock then it makes sense to call the wait () method in the object. If the wait () method is defined in the Thread class, it is not obvious which lock the thread is waiting for. Simply put, since wait, notify, and notifyAll are lock-level operations, they are defined in the Object class because the lock belongs to the object.
————————————————
Original link: https://blog.csdn.net/pulusite/java/article/details/82287462

Guess you like

Origin www.cnblogs.com/breakingbrad/p/12711800.html