Introduction to basic principles to achieve AbstractQueuedSynchronizer class of Java Concurrency Control

1. primer

The main class that implements internal ReentrantLock Lock interface is the use of a member variable of type Sync to sync commissioned implement Lock lock interface, and Sync inherited from AbstractQueuedSynchronizer, concurrency tools in use and most of all java.util.concurrent package AbstractQueuedSynchronizer synchronization is achieved. To understand the principle of concurrency, you must first clear implementation mechanism of AbstractQueuedSynchronizer.

 

 2. The synchronizer parent AbstractQueuedSynchronizer

AbstractQueuedSynchronizer immediate parent class is AbstractOwnableSynchronizer.

 AbstractOwnableSynchronizer class definition

    public abstract class AbstractOwnableSynchronizer
            implements java.io.Serializable {

        private static final long serialVersionUID = 3737899427754241961L;

        protected AbstractOwnableSynchronizer() {
        }

        private transient Thread exclusiveOwnerThread;

        protected final void setExclusiveOwnerThread(Thread thread) {
            exclusiveOwnerThread = thread;
        }

        protected final Thread getExclusiveOwnerThread() {
            return exclusiveOwnerThread;
        }
    }

 

 This class only one pair of setter Thread type exclusiveOwnerThread member variable / getter method is used to set / get exclusive threads, as its name of "Ownable", such is the "one thread might proprietary synchronizer." This / getter setter particularly useful for an exclusive lock type of concurrency utilities. And a reentrant ReentrantLock exclusive lock (also called exclusive lock exclusive lock), and therefore such ReentrantLock commonly to both methods.

 

Synchronizer AbstractQueuedSynchronizer dependent inside the synchronous queue (a bidirectional FIFO queue) to complete the synchronization status management

Guess you like

Origin www.cnblogs.com/gocode/p/12189741.html