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 Summary
Constructors Constructor Description AbstractReadWriteLockManager()
Creates a MultiReadSingleWriteLockManager.AbstractReadWriteLockManager(boolean trackLocks)
Creates a new MultiReadSingleWriteLockManager, optionally with lock tracking enabled.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Lock
createReadLock()
Creates a new Lock for reading and increments counter for active readers.protected Lock
createWriteLock()
Creates a new Lock for writing.protected boolean
isReaderActive()
If one or more readers are activeprotected boolean
isWriterActive()
If a writer is activeprotected void
waitForActiveReaders()
Blocks current thread until there are no reader locks active.protected void
waitForActiveWriter()
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 Detail
-
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 Detail
-
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.
-
-