Class StampedLockManager

  • All Implemented Interfaces:
    ReadWriteLockManager

    @Experimental
    public class StampedLockManager
    extends java.lang.Object
    implements ReadWriteLockManager
    A read/write-lock manager backed by a StampedLock.

    This class is in an experimental state: its existence, signature or behavior may change without warning from one release to the next.

    • Constructor Detail

      • StampedLockManager

        public StampedLockManager()
      • StampedLockManager

        public StampedLockManager​(boolean trackLocks)
      • StampedLockManager

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

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

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

      • 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.
      • createReadLockInner

        private StampedLockManager.ReadLock createReadLockInner()
                                                         throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • getOptimisticReadLock

        public StampedLockManager.OptimisticReadLock getOptimisticReadLock()
        Gets an optimistic read lock, if available. This method will return null if the optimistic read lock is not immediately available.
      • convertToReadLock

        public Lock convertToReadLock​(Lock writeLock)
        Convert a write lock to a read lock.
      • 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.
      • createWriteLockInner

        private StampedLockManager.WriteLock createWriteLockInner()
                                                           throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • 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

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