public class UpdateLock extends Object implements InterProcessLock
| Constructor and Description |
|---|
UpdateLock() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isHeld()
Returns if this lock is held by any thread.
|
boolean |
isHeldByCurrentThread()
Checks if this lock is held by current thread.
|
void |
lock()
Acquires the lock.
|
void |
lockInterruptibly()
Acquires the lock unless the current thread is interrupted.
|
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 (and all stronger-level lock, in the context of
InterProcessReadWriteUpdateLock, if the lock is not held by the current thread, returns
immediately. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitnewConditionpublic boolean isHeldByCurrentThread()
InterProcessLockisHeldByCurrentThread in interface InterProcessLockpublic void lock()
InterProcessLockInterProcessReadWriteUpdateLock) is already held by the current thread, this call returns
immediately.
If the lock is not available then the current thread enters a busy loop. After some
threshold time spent in a busy loop, the thread might be disabled for thread
scheduling purposes and lay dormant until the lock has been acquired. After some
implementation-defined time spent in waiting for the lock acquisition,
InterProcessDeadLockException is thrown.
lock in interface Locklock in interface InterProcessLockpublic void lockInterruptibly()
throws InterruptedException
InterProcessLockInterProcessReadWriteUpdateLock) is already held by the current thread,
this call returns immediately.
If the lock is not available then the current thread enters a busy loop, and after some threshold time spend in a busy loop, the thread might be disabled for thread scheduling purposes and lay dormant until one of three things happens:
lockInterruptibly() successfully
returns.
InterruptedException is thrown and the current thread's interrupted status is
cleared.
InterProcessDeadLockException is thrown.
lockInterruptibly in interface LocklockInterruptibly in interface InterProcessLockInterruptedException - if the current thread is interrupted while acquiring the lockpublic boolean tryLock()
InterProcessLocktrue.
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 LocktryLock in interface InterProcessLocktrue if the lock was acquired and false otherwisepublic boolean tryLock(long time,
@NotNull
TimeUnit unit)
throws InterruptedException
tryLock in interface LockInterruptedExceptionpublic void unlock()
InterProcessLockInterProcessReadWriteUpdateLock, if the lock is not held by the current thread, returns
immediately.unlock in interface Lockunlock in interface InterProcessLockpublic boolean isHeld()
InterProcessLockisHeld in interface InterProcessLockCopyright © 2024. All rights reserved.