Class AbstractReadWriteLockManager
java.lang.Object
org.eclipse.rdf4j.common.concurrent.locks.AbstractReadWriteLockManager
- All Implemented Interfaces:
ReadWriteLockManager
- Direct Known Subclasses:
ReadPrefReadWriteLockManager
,WritePrefReadWriteLockManager
An abstract base implementation of a read/write lock manager.
- Author:
- Arjohn Kampman, James Leigh
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a MultiReadSingleWriteLockManager.AbstractReadWriteLockManager(boolean trackLocks)
Creates a new MultiReadSingleWriteLockManager, optionally with lock tracking enabled. -
Method Summary
Modifier and TypeMethodDescriptionprotected Lock
Creates a new Lock for reading and increments counter for active readers.protected Lock
Creates a new Lock for writing.protected boolean
If one or more readers are activeprotected boolean
If a writer is activeprotected void
Blocks current thread until there are no reader locks active.protected void
Blocks current thread until after the writer lock is released (if active).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.rdf4j.common.concurrent.locks.ReadWriteLockManager
getReadLock, getWriteLock, tryReadLock, tryWriteLock
-
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
Blocks current thread until after the writer lock is released (if active).- Throws:
InterruptedException
-
waitForActiveReaders
Blocks current thread until there are no reader locks active.- Throws:
InterruptedException
-
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
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.
-