public class NonOptimisticLock extends Object implements OptimisticLock
StampedLock
is not available. This
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 |
---|---|
boolean |
canCheckHolder()
True if this lock supports
OptimisticLock.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()
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()
OptimisticLock
readLock
in interface OptimisticLock
public long writeLock()
OptimisticLock
writeLock
in interface OptimisticLock
public long tryOptimisticRead()
tryOptimisticRead
in interface OptimisticLock
public boolean validate(long stamp)
validate
in interface OptimisticLock
stamp
- a stamptrue
if the lock has not been exclusively acquired
since issuance of the given stamp; else falsepublic void unlockRead(long stamp)
OptimisticLock
unlockRead
in interface OptimisticLock
stamp
- a stamp returned by a read-lock operationpublic void unlockWrite(long stamp)
OptimisticLock
unlockWrite
in interface OptimisticLock
stamp
- a stamp returned by a write-lock operationpublic boolean canCheckHolder()
OptimisticLock
OptimisticLock.isHoldingWriteLock()
canCheckHolder
in interface OptimisticLock
public boolean isHoldingWriteLock()
OptimisticLock
isHoldingWriteLock
in interface OptimisticLock
cache2k API documentation. Copyright © 2000–2018 headissue GmbH, Munich.