public interface OptimisticLock
StampedLock
The implementation may support optimistic locking if available at
the platform. If not supported, validate(long)
returns always false.
This allows the identical usage pattern for both variants.
The implementation may support owner checks with isHoldingWriteLock()
.
This can be used for debugging.
Modifier and Type | Method and Description |
---|---|
boolean |
canCheckHolder()
True if this lock supports
isHoldingWriteLock() |
boolean |
isHoldingWriteLock()
Checks whether current thread is holding the write lock.
|
long |
readLock()
Non-exclusively acquires the lock, blocking if necessary
until available.
|
long |
tryOptimisticRead()
Returns a stamp that can later be validated, or zero
if exclusively locked.
|
void |
unlockRead(long stamp)
If the lock state matches the given stamp, releases the
non-exclusive lock.
|
void |
unlockWrite(long stamp)
If the lock state matches the given stamp, releases the
exclusive lock.
|
boolean |
validate(long stamp)
Returns true if the lock has not been exclusively acquired
since issuance of the given stamp.
|
long |
writeLock()
Exclusively acquires the lock, blocking if necessary
until available.
|
long writeLock()
long readLock()
long tryOptimisticRead()
unlockWrite(long)
become visible.boolean validate(long stamp)
tryOptimisticRead()
or a locking method
for this lock has no defined effect or result.stamp
- a stamptrue
if the lock has not been exclusively acquired
since issuance of the given stamp; else falsevoid unlockRead(long stamp)
stamp
- a stamp returned by a read-lock operationIllegalMonitorStateException
- if the stamp does
not match the current state of this lockvoid unlockWrite(long stamp)
stamp
- a stamp returned by a write-lock operationIllegalMonitorStateException
- if the stamp does
not match the current state of this lockboolean canCheckHolder()
isHoldingWriteLock()
boolean isHoldingWriteLock()
cache2k API documentation. Copyright © 2000–2018 headissue GmbH, Munich.