Lock interface
Api:lock (), Unlock () ....
Abstractqueuedsynchronizer Queue Synchronizer
The Synchronizer is designed based on the template method pattern, that is, the consumer needs to inherit the Synchronizer and override the specified method, then combine the Synchronizer in the implementation of the custom synchronization component and invoke the template method provided by the Synchronizer, which will invoke the method overridden by the consumer.
Overridable methods:
protected Boolean tryacquire (int arg)
protected Boolean tryrelease (int arg)
protected int tryacquireshared (int arg)
protected Boolean tryreleaseshared (int arg)
Protected Boolean isheldexclusively ()
In the overridden method, when you need to make changes to the synchronization, you can use the three methods provided by the Synchronizer to safely change the synchronization state:
GetState ()
SetState ()
Compareandsetstate ()
Re-entry Lock
Read/write Lock Locksupportcondition interface
Locks in Java