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 LongAdder
private final LockMonitoring
<AbstractReadWriteLockManager.ReadLock> (package private) final StampedLock
private final int
private final LockMonitoring
<AbstractReadWriteLockManager.WriteLock> (package private) final int
When 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.ReadLock
Gets a read lock.Gets an exclusive write lock.(package private) abstract int
boolean
Returnsfalse
if there are no active read locks, otherwise returnstrue
.boolean
Returnsfalse
if there are no active write locks, otherwise returnstrue
.(package private) void
spinWait()
(package private) void
Gets a read lock, if available.Gets an exclusive write lock, if available.void
Blocks until all read locks have been released.void
Blocks until all write locks have been released.private long
private 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()Returnsfalse
if there are no active write locks, otherwise returnstrue
.- Specified by:
isWriterActive
in interfaceReadWriteLockManager
-
isReaderActive
public boolean isReaderActive()Returnsfalse
if there are no active read locks, otherwise returnstrue
.- Specified by:
isReaderActive
in interfaceReadWriteLockManager
-
waitForActiveWriter
Blocks until all write locks have been released.- Specified by:
waitForActiveWriter
in interfaceReadWriteLockManager
- Throws:
InterruptedException
- In case the thread requesting the lock wasinterrupted
.
-
waitForActiveReaders
Blocks until all read locks have been released.- Specified by:
waitForActiveReaders
in 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:
getReadLock
in 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:
getWriteLock
in 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:
tryReadLock
in 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:
tryWriteLock
in interfaceReadWriteLockManager
-
tryWriteLockInner
-
spinWait
- Throws:
InterruptedException
-
spinWaitAtReadLock
- Throws:
InterruptedException
-
yieldWait
- Throws:
InterruptedException
-