AsyncNamedReadWriteLock<T>
public class FairAsyncNamedReadWriteLock<T> extends Object implements AsyncNamedReadWriteLock<T>
AsyncNamedReadWriteLock
interface which enforces fair
acquisitions (i.e. readers will queue behind waiting writers to prevent writer starvation).
null
values are not permitted for use as names.
Constructor | Description |
---|---|
FairAsyncNamedReadWriteLock() |
Modifier and Type | Method | Description |
---|---|---|
CompletionStage<AsyncReadWriteLock.ReadLockToken> |
acquireReadLock(T name) |
Acquires the read lock associated with the given name.
|
CompletionStage<AsyncReadWriteLock.WriteLockToken> |
acquireWriteLock(T name) |
Exclusively acquires the write lock associated with the given name.
|
Optional<AsyncReadWriteLock.ReadLockToken> |
tryReadLock(T name) |
Attempts to acquire the read lock associated with the given name.
|
Optional<AsyncReadWriteLock.WriteLockToken> |
tryWriteLock(T name) |
Attempts to acquire the write lock associated with the given name.
|
create, createFair
public CompletionStage<AsyncReadWriteLock.ReadLockToken> acquireReadLock(T name)
AsyncNamedReadWriteLock
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 AsyncNamedReadWriteLock<T>
name
- to acquire read access forCompletionStage
which will complete with a
AsyncReadWriteLock.ReadLockToken
when the read lock associated with
name
has been acquiredpublic CompletionStage<AsyncReadWriteLock.WriteLockToken> acquireWriteLock(T name)
AsyncNamedReadWriteLock
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 AsyncNamedReadWriteLock<T>
name
- to acquire exclusive write access forCompletionStage
which will complete with a
AsyncReadWriteLock.WriteLockToken
when the lock associated with name
has been exclusively acquiredpublic Optional<AsyncReadWriteLock.ReadLockToken> tryReadLock(T name)
AsyncNamedReadWriteLock
The AsyncReadWriteLock.ReadLockToken
held by the returned optional is used to release
the read lock after it has been acquired and the read-lock-protected action has completed.
tryReadLock
in interface AsyncNamedReadWriteLock<T>
name
- to acquire read access forOptional
holding a AsyncReadWriteLock.ReadLockToken
if the write
lock associated with name
is not held; otherwise an empty Optionalpublic Optional<AsyncReadWriteLock.WriteLockToken> tryWriteLock(T name)
AsyncNamedReadWriteLock
The AsyncReadWriteLock.WriteLockToken
held by the returned optional is used to release
the write lock after it has been acquired and the write-lock-protected action has completed.
tryWriteLock
in interface AsyncNamedReadWriteLock<T>
name
- to acquire exclusive write access forOptional
holding a AsyncReadWriteLock.WriteLockToken
if the lock
associated with name
is not held by a writer or any readers; otherwise an empty
OptionalCopyright © 2018. All rights reserved.