Lock pool and pool waiting
For each object for the program running in the JVM has two pools: pool locks EntryList, waiting pool WaitSet, two pools which in turn Object class wait (), notify (), notifyAll () method of three and about the synchronized keyword.
-
锁池 EntryList
Thread A has assumed a certain object (not the class) of the lock, while the other thread B, C wants to call a synchronized method of this object (or block), since the B, C thread synchronized way into the subject (or must be obtained before the block) ownership of the object lock, which happens to lock the object is currently being occupied by the thread a, while the B, C thread will be blocked into a place to wait to release the lock, this is the place the object's lock pool
-
Wait pool WaitSet
A thread calls the wait is assumed that an object () method, thread A releases the lock of the object while thread A enters into a waiting pool of the object, the thread into the wait pool object is not to compete with the locks.
The difference notify and notifyAll
notify only randomly selected opportunities in a thread waiting to enter the lock pool to pool competition to obtain the lock
NotifyAll opportunity to make all the threads in a wait pool are locked into the pool to compete to acquire a lock