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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final LongAdder(package private) final LongAdderprivate final LockMonitoring<AbstractReadWriteLockManager.ReadLock> (package private) final StampedLockprivate final intprivate final LockMonitoring<AbstractReadWriteLockManager.WriteLock> (package private) final intWhen acquiring a write-lock, the thread will acquire the write-lock and then spin invalid input: '&' yield while waiting for readers to unlock their locks. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractReadWriteLockManager(boolean trackLocks) AbstractReadWriteLockManager(boolean trackLocks, int waitToCollect) AbstractReadWriteLockManager(String alias, int waitToCollect, LockDiagnostics... lockDiagnostics) AbstractReadWriteLockManager(String alias, LockDiagnostics... lockDiagnostics) -
Method Summary
Modifier and TypeMethodDescription(package private) AbstractReadWriteLockManager.ReadLockGets a read lock.Gets an exclusive write lock.(package private) abstract intbooleanReturnsfalseif there are no active read locks, otherwise returnstrue.booleanReturnsfalseif there are no active write locks, otherwise returnstrue.(package private) voidspinWait()(package private) voidGets a read lock, if available.Gets an exclusive write lock, if available.voidBlocks until all read locks have been released.voidBlocks until all write locks have been released.private longprivate void
-
Field Details
-
readLockMonitoring
-
writeLockMonitoring
-
stampedLock
-
readersLocked
-
readersUnlocked
-
tryWriteLockMillis
private final int tryWriteLockMillis -
writePreference
final int writePreferenceWhen acquiring a write-lock, the thread will acquire the write-lock and then spin invalid input: '&' 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 invalid input: '&' yield 100 times before it attempts to release the write-lock.
-
-
Constructor Details
-
AbstractReadWriteLockManager
public AbstractReadWriteLockManager() -
AbstractReadWriteLockManager
public AbstractReadWriteLockManager(boolean trackLocks) -
AbstractReadWriteLockManager
public AbstractReadWriteLockManager(boolean trackLocks, int waitToCollect) -
AbstractReadWriteLockManager
-
AbstractReadWriteLockManager
public AbstractReadWriteLockManager(String alias, int waitToCollect, LockDiagnostics... lockDiagnostics)
-
-
Method Details
-
getWriterPreference
abstract int getWriterPreference() -
isWriterActive
public boolean isWriterActive()Returnsfalseif there are no active write locks, otherwise returnstrue.- Specified by:
isWriterActivein interfaceReadWriteLockManager
-
isReaderActive
public boolean isReaderActive()Returnsfalseif there are no active read locks, otherwise returnstrue.- Specified by:
isReaderActivein interfaceReadWriteLockManager
-
waitForActiveWriter
Blocks until all write locks have been released.- Specified by:
waitForActiveWriterin interfaceReadWriteLockManager- Throws:
InterruptedException- In case the thread requesting the lock wasinterrupted.
-
waitForActiveReaders
Blocks until all read locks have been released.- Specified by:
waitForActiveReadersin interfaceReadWriteLockManager- Throws:
InterruptedException- In case the thread requesting the lock wasinterrupted.
-
getReadLock
Gets a read lock. This method blocks until the read lock is available.- Specified by:
getReadLockin interfaceReadWriteLockManager- Throws:
InterruptedException- In case the thread requesting the lock wasinterrupted.
-
createReadLockInner
- Throws:
InterruptedException
-
getWriteLock
Gets an exclusive write lock. This method blocks until the write lock is available.- Specified by:
getWriteLockin interfaceReadWriteLockManager- Throws:
InterruptedException- In case the thread requesting the lock wasinterrupted.
-
createWriteLockInner
- Throws:
InterruptedException
-
writeLockInterruptibly
- Throws:
InterruptedException
-
tryReadLock
Gets a read lock, if available. This method will return null if the read lock is not immediately available.- Specified by:
tryReadLockin interfaceReadWriteLockManager
-
tryReadLockInner
-
tryWriteLock
Gets an exclusive write lock, if available. This method will return null if the write lock is not immediately available.- Specified by:
tryWriteLockin interfaceReadWriteLockManager
-
tryWriteLockInner
-
spinWait
- Throws:
InterruptedException
-
spinWaitAtReadLock
- Throws:
InterruptedException
-
yieldWait
- Throws:
InterruptedException
-