Class AbstractReadWriteLockManager

java.lang.Object
org.eclipse.rdf4j.common.concurrent.locks.AbstractReadWriteLockManager
All Implemented Interfaces:
ReadWriteLockManager
Direct Known Subclasses:
ReadPrefReadWriteLockManager, WritePrefReadWriteLockManager

public abstract class AbstractReadWriteLockManager extends Object implements ReadWriteLockManager
An abstract base implementation of a read/write lock manager.
Author:
Arjohn Kampman, James Leigh
  • Constructor Details

    • AbstractReadWriteLockManager

      public AbstractReadWriteLockManager()
      Creates a MultiReadSingleWriteLockManager.
    • AbstractReadWriteLockManager

      public AbstractReadWriteLockManager(boolean trackLocks)
      Creates a new MultiReadSingleWriteLockManager, optionally with lock tracking enabled.
      Parameters:
      trackLocks - Controls whether the lock manager will keep track of active locks. Enabling lock tracking will add some overhead, but can be very useful for debugging.
  • Method Details

    • isWriterActive

      protected boolean isWriterActive()
      If a writer is active
    • isReaderActive

      protected boolean isReaderActive()
      If one or more readers are active
    • waitForActiveWriter

      protected void waitForActiveWriter() throws InterruptedException
      Blocks current thread until after the writer lock is released (if active).
      Throws:
      InterruptedException
    • waitForActiveReaders

      protected void waitForActiveReaders() throws InterruptedException
      Blocks current thread until there are no reader locks active.
      Throws:
      InterruptedException
    • createReadLock

      protected Lock createReadLock()
      Creates a new Lock for reading and increments counter for active readers. The lock is tracked if lock tracking is enabled. This method is not thread safe itself, the calling method is expected to handle synchronization issues.
      Returns:
      a read lock.
    • createWriteLock

      protected Lock createWriteLock()
      Creates a new Lock for writing. The lock is tracked if lock tracking is enabled. This method is not thread safe itself for performance reasons, the calling method is expected to handle synchronization issues.
      Returns:
      a write lock.