public class CompiledMapQueryContext.ReadLock extends Object implements InterProcessLock
Constructor and Description |
---|
ReadLock() |
Modifier and Type | Method and Description |
---|---|
void |
closeReadLockLockDependants() |
boolean |
isHeldByCurrentThread()
Checks if this lock is held by current thread.
|
void |
lock()
Acquires the lock, if this lock (or stronger-level lock, in the context of
InterProcessReadWriteUpdateLock ) is already held by current thread, this call returns
immediately. |
void |
lockInterruptibly() |
boolean |
tryLock()
Acquires the lock only if it is free at the time of invocation, also if the lock is already
held by the current thread, this call immediately returns
true . |
boolean |
tryLock(long time,
TimeUnit unit) |
void |
unlock()
Releases the lock, if the lock is not held by the current thread, returns immediately.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
newCondition
public boolean isHeldByCurrentThread()
InterProcessLock
isHeldByCurrentThread
in interface InterProcessLock
public void lockInterruptibly() throws InterruptedException
lockInterruptibly
in interface Lock
InterruptedException
public void lock()
InterProcessLock
InterProcessReadWriteUpdateLock
) is already held by current thread, this call returns
immediately.
If the lock is not available then the current thread enter a busy loop. After some
specified threshold, the thread might be disabled for thread scheduling purposes
and lies dormant until the lock has been acquired. After another specified threshold
RuntimeException
is thrown.
lock
in interface Lock
lock
in interface InterProcessLock
public void closeReadLockLockDependants()
public void unlock()
InterProcessLock
unlock
in interface Lock
unlock
in interface InterProcessLock
public boolean tryLock(long time, @NotNull TimeUnit unit) throws InterruptedException
tryLock
in interface Lock
InterruptedException
public boolean tryLock()
InterProcessLock
true
.
Acquires the lock if it is available and returns immediately
with the value true
.
If the lock is not available then this method will return
immediately with the value false
.
Example usage:
try (ExternalMapQueryContext<K, V, ?> q = map.queryContext(key)) {
if (q.updateLock().tryLock()) {
// highly-probable branch
if (q.entry() != null) {
// upgrade to write lock
q.writeLock().lock();
q.remove(q.entry());
} else {
// ...
}
} else {
// if failed to acquire the update lock without waiting, go acquire the write lock
// right away, because probability that we will need to upgrade to write lock anyway
// is high.
q.writeLock().lock();
if (q.entry() != null) {
q.remove(q.entry());
} else {
// ...
}
}
}
tryLock
in interface Lock
tryLock
in interface InterProcessLock
true
if the lock was acquired and false
otherwiseCopyright © 2015. All rights reserved.