Class AbstractReadWriteLockManager

    • Field Detail

      • stampedLock

        final java.util.concurrent.locks.StampedLock stampedLock
      • readersLocked

        final java.util.concurrent.atomic.LongAdder readersLocked
      • readersUnlocked

        final java.util.concurrent.atomic.LongAdder readersUnlocked
      • tryWriteLockMillis

        private final int tryWriteLockMillis
      • writePreference

        final int writePreference
        When acquiring a write-lock, the thread will acquire the write-lock and then spin & yield while waiting for readers to unlock their locks. A deadlock is possible if someone already holding a read-lock acquires another read-lock at the same time that another thread is waiting for a write-lock. To stop this from happening we can set READ_PREFERENCE to a number higher than zero. READ_PREFERENCE of 1 means that the thread acquiring a write-lock will release the write-lock if there are any readers. A READ_PREFERENCE of 100 means that the thread acquiring a write-lock will spin & yield 100 times before it attempts to release the write-lock.
    • Constructor Detail

      • AbstractReadWriteLockManager

        public AbstractReadWriteLockManager()
      • AbstractReadWriteLockManager

        public AbstractReadWriteLockManager​(boolean trackLocks)
      • AbstractReadWriteLockManager

        public AbstractReadWriteLockManager​(boolean trackLocks,
                                            int waitToCollect)
      • AbstractReadWriteLockManager

        public AbstractReadWriteLockManager​(java.lang.String alias,
                                            LockDiagnostics... lockDiagnostics)
      • AbstractReadWriteLockManager

        public AbstractReadWriteLockManager​(java.lang.String alias,
                                            int waitToCollect,
                                            LockDiagnostics... lockDiagnostics)
    • Method Detail

      • getWriterPreference

        abstract int getWriterPreference()
      • isWriterActive

        public boolean isWriterActive()
        Returns false if there are no active write locks, otherwise returns true.
        Specified by:
        isWriterActive in interface ReadWriteLockManager
      • isReaderActive

        public boolean isReaderActive()
        Returns false if there are no active read locks, otherwise returns true.
        Specified by:
        isReaderActive in interface ReadWriteLockManager
      • waitForActiveWriter

        public void waitForActiveWriter()
                                 throws java.lang.InterruptedException
        Blocks until all write locks have been released.
        Specified by:
        waitForActiveWriter in interface ReadWriteLockManager
        Throws:
        java.lang.InterruptedException - In case the thread requesting the lock was interrupted.
      • waitForActiveReaders

        public void waitForActiveReaders()
                                  throws java.lang.InterruptedException
        Blocks until all read locks have been released.
        Specified by:
        waitForActiveReaders in interface ReadWriteLockManager
        Throws:
        java.lang.InterruptedException - In case the thread requesting the lock was interrupted.
      • getReadLock

        public Lock getReadLock()
                         throws java.lang.InterruptedException
        Gets a read lock. This method blocks until the read lock is available.
        Specified by:
        getReadLock in interface ReadWriteLockManager
        Throws:
        java.lang.InterruptedException - In case the thread requesting the lock was interrupted.
      • getWriteLock

        public Lock getWriteLock()
                          throws java.lang.InterruptedException
        Gets an exclusive write lock. This method blocks until the write lock is available.
        Specified by:
        getWriteLock in interface ReadWriteLockManager
        Throws:
        java.lang.InterruptedException - In case the thread requesting the lock was interrupted.
      • writeLockInterruptibly

        private long writeLockInterruptibly()
                                     throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • tryReadLock

        public Lock tryReadLock()
        Gets a read lock, if available. This method will return null if the read lock is not immediately available.
        Specified by:
        tryReadLock in interface ReadWriteLockManager
      • tryWriteLock

        public Lock tryWriteLock()
        Gets an exclusive write lock, if available. This method will return null if the write lock is not immediately available.
        Specified by:
        tryWriteLock in interface ReadWriteLockManager
      • spinWait

        void spinWait()
               throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • spinWaitAtReadLock

        void spinWaitAtReadLock()
                         throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • yieldWait

        private void yieldWait()
                        throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException