AsyncReadWriteLock
FairAsyncStampedLock
public class FairAsyncReadWriteLock extends Object implements AsyncReadWriteLock
AsyncReadWriteLock
interface which enforces reader/writer
fairness -- i.e. new readers will queue behind waiting writersAsyncReadWriteLock.ReadLockToken, AsyncReadWriteLock.WriteLockToken
Constructor | Description |
---|---|
FairAsyncReadWriteLock() |
Modifier and Type | Method | Description |
---|---|---|
CompletionStage<AsyncReadWriteLock.ReadLockToken> |
acquireReadLock() |
Acquires this read lock.
|
CompletionStage<AsyncReadWriteLock.WriteLockToken> |
acquireWriteLock() |
Exclusively acquires this write lock.
|
Optional<AsyncReadWriteLock.ReadLockToken> |
tryReadLock() |
Attempt to immediately acquire the read lock, returning a populated
Optional if the
lock is not currently held by a writer and there are no writers queued in waiting (i.e. |
Optional<AsyncReadWriteLock.WriteLockToken> |
tryWriteLock() |
Attempts to immediately acquire the write lock, returning a populated
Optional if the
lock is not currently held by a writer or any readers. |
create, createFair
public final CompletionStage<AsyncReadWriteLock.ReadLockToken> acquireReadLock()
AsyncReadWriteLock
The AsyncReadWriteLock.ReadLockToken
held by the returned stage is used to release the read lock after it
has been acquired and the read-lock-protected action has completed.
acquireReadLock
in interface AsyncReadWriteLock
CompletionStage
which will complete with a AsyncReadWriteLock.ReadLockToken
when the
read lock has been acquiredpublic final Optional<AsyncReadWriteLock.ReadLockToken> tryReadLock()
Optional
if the
lock is not currently held by a writer and there are no writers queued in waiting (i.e. this
acquire is "fair" and will not barge ahead of waiting writers).tryReadLock
in interface AsyncReadWriteLock
Optional
holding a AsyncReadWriteLock.ReadLockToken
if the lock is not held by a
writer; otherwise an empty Optionalpublic final CompletionStage<AsyncReadWriteLock.WriteLockToken> acquireWriteLock()
AsyncReadWriteLock
The AsyncReadWriteLock.WriteLockToken
held by the returned stage is used to release the write lock after
it has been acquired and the write-lock-protected action has completed.
acquireWriteLock
in interface AsyncReadWriteLock
CompletionStage
which will complete with a AsyncReadWriteLock.WriteLockToken
when the
write lock has been exclusively acquiredpublic final Optional<AsyncReadWriteLock.WriteLockToken> tryWriteLock()
AsyncReadWriteLock
Optional
if the
lock is not currently held by a writer or any readers.tryWriteLock
in interface AsyncReadWriteLock
Optional
holding a AsyncReadWriteLock.WriteLockToken
if the lock is not held by a
writer or any readers; otherwise an empty OptionalCopyright © 2018. All rights reserved.