public class NonOptimisticLock extends Object implements OptimisticLock
StampedLock is not available. This
lock denies optimistic locking and uses a single write lock.
Optimistic locking is only possible on a Java 8 VM that support the
loadFence instructions. Otherwise loads might get reordered after
the validate, causing wrong results.
| Constructor and Description |
|---|
NonOptimisticLock() |
| Modifier and Type | Method and Description |
|---|---|
long |
readLock()
Non-exclusively acquires the lock, blocking if necessary
until available.
|
long |
tryOptimisticRead()
This is a read access on the lock state for data visibility.
|
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)
Always false, optimistic locking not supported.
|
long |
writeLock()
Exclusively acquires the lock, blocking if necessary
until available.
|
public long readLock()
OptimisticLockreadLock in interface OptimisticLockpublic long writeLock()
OptimisticLockwriteLock in interface OptimisticLockpublic long tryOptimisticRead()
tryOptimisticRead in interface OptimisticLockpublic boolean validate(long stamp)
validate in interface OptimisticLockstamp - a stamptrue if the lock has not been exclusively acquired
since issuance of the given stamp; else falsepublic void unlockRead(long stamp)
OptimisticLockunlockRead in interface OptimisticLockstamp - a stamp returned by a read-lock operationpublic void unlockWrite(long stamp)
OptimisticLockunlockWrite in interface OptimisticLockstamp - a stamp returned by a write-lock operationcache2k API documentation. Copyright © 2000–2019 headissue GmbH, Munich.