object's monitor

 

 

http://ifeve.com/monitors-java-synchronization-mechanism/

 

The monitor is used for synchronization, it is a mechanism, not an object, but we have a saying of "obtaining the monitor of the object", (just accept)

 

The monitor is obtained through the synchronzied keyword

 

--------

wait

 

The current thread must own this object monitor. This thread releases ownership of this monitor and waits until notifyanother notifyAllthread wakes up by calling the method, or method notifying the thread waiting on this object's monitor. The thread will then wait until it regains ownership of the monitor before continuing.

 

--------

notify

 

Wakes up a single thread waiting on this object's monitor. If all threads are waiting on this object, one of them will be chosen to wake up. The choice is arbitrary and happens when a decision is made on the implementation. The thread waits on the object's monitor by calling one of the waitmethods  .

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326841058&siteId=291194637