Class AtomicReadWriteLock

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.atomic.AtomicInteger readCount
      The count of readers.
      protected int sink
      The field for consuming CPU.
      protected java.util.concurrent.atomic.AtomicInteger writeCount
      The count of writers.
      protected java.util.concurrent.atomic.AtomicInteger writeStatus
      The status of write lock.
    • Constructor Summary

      Constructors 
      Constructor Description
      AtomicReadWriteLock()
      Instantiates a new Atomic read write lock.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void asyncLock()
      Lock any writing for reading.
      void asyncUnlock()
      Finish this reading and unlock any writing if it is last reading.
      protected void consumeCPU()
      Consume cpu.
      void lock()  
      void lockInterruptibly()  
      java.util.concurrent.locks.Condition newCondition()  
      void syncLock()
      Lock any reading for writing.
      void syncUnlock()
      Finish this writing and unlock any readings.
      java.lang.String toString()  
      boolean tryLock()  
      boolean tryLock​(long time, java.util.concurrent.TimeUnit unit)  
      protected boolean tryToLockReading()
      Try to lock reading boolean.
      protected boolean tryToLockWriting()
      Try to lock writing boolean.
      void unlock()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • writeStatus

        protected final java.util.concurrent.atomic.AtomicInteger writeStatus
        The status of write lock.
      • writeCount

        protected final java.util.concurrent.atomic.AtomicInteger writeCount
        The count of writers.
      • readCount

        protected final java.util.concurrent.atomic.AtomicInteger readCount
        The count of readers.
      • sink

        protected int sink
        The field for consuming CPU.
    • Constructor Detail

      • AtomicReadWriteLock

        public AtomicReadWriteLock()
        Instantiates a new Atomic read write lock.
    • Method Detail

      • consumeCPU

        protected void consumeCPU()
        Consume cpu.
      • lock

        public void lock()
        Specified by:
        lock in interface java.util.concurrent.locks.Lock
      • lockInterruptibly

        public void lockInterruptibly()
                               throws java.lang.InterruptedException
        Specified by:
        lockInterruptibly in interface java.util.concurrent.locks.Lock
        Throws:
        java.lang.InterruptedException
      • newCondition

        public java.util.concurrent.locks.Condition newCondition()
        Specified by:
        newCondition in interface java.util.concurrent.locks.Lock
      • tryToLockWriting

        protected boolean tryToLockWriting()
        Try to lock writing boolean.
        Returns:
        the boolean
      • tryToLockReading

        protected boolean tryToLockReading()
        Try to lock reading boolean.
        Returns:
        the boolean
      • tryLock

        public boolean tryLock()
        Specified by:
        tryLock in interface java.util.concurrent.locks.Lock
      • tryLock

        public boolean tryLock​(long time,
                               java.util.concurrent.TimeUnit unit)
                        throws java.lang.InterruptedException
        Specified by:
        tryLock in interface java.util.concurrent.locks.Lock
        Throws:
        java.lang.InterruptedException
      • unlock

        public void unlock()
        Specified by:
        unlock in interface java.util.concurrent.locks.Lock
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object