public final class ConcurrentUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static <T> boolean |
releaseLock(java.util.concurrent.atomic.AtomicIntegerFieldUpdater<T> lockUpdater,
T owner)
Release a lock that was previously acquired via
tryAcquireLock(AtomicIntegerFieldUpdater, Object) . |
static <T> boolean |
releaseReentrantLock(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> lockUpdater,
long acquireId,
T owner)
Release a lock that was previously acquired via
tryAcquireReentrantLock(AtomicLongFieldUpdater, Object) . |
static <T> boolean |
tryAcquireLock(java.util.concurrent.atomic.AtomicIntegerFieldUpdater<T> lockUpdater,
T owner)
Acquire a lock that is exclusively held with no re-entry, but attempts to acquire the lock while it is
held can be detected by
releaseLock(AtomicIntegerFieldUpdater, Object) . |
static <T> long |
tryAcquireReentrantLock(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> lockUpdater,
T owner)
Acquire a lock that allows reentry and attempts to acquire the lock while it is
held can be detected by
releaseReentrantLock(AtomicLongFieldUpdater, long, Object) . |
public static <T> boolean tryAcquireLock(java.util.concurrent.atomic.AtomicIntegerFieldUpdater<T> lockUpdater, T owner)
releaseLock(AtomicIntegerFieldUpdater, Object)
.T
- The type of object that owns the lock.lockUpdater
- The AtomicIntegerFieldUpdater
used to control the lock state.owner
- The owner of the lock object.true
if the lock was acquired, false
otherwise.public static <T> boolean releaseLock(java.util.concurrent.atomic.AtomicIntegerFieldUpdater<T> lockUpdater, T owner)
tryAcquireLock(AtomicIntegerFieldUpdater, Object)
.T
- The type of object that owns the lock.lockUpdater
- The AtomicIntegerFieldUpdater
used to control the lock state.owner
- The owner of the lock object.true
if the lock was released, and no other attempts were made to acquire the lock while it
was held. false
if the lock was released but another attempt was made to acquire the lock before it was
released.public static <T> long tryAcquireReentrantLock(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> lockUpdater, T owner)
releaseReentrantLock(AtomicLongFieldUpdater, long, Object)
.
This lock must eventually be released by the same thread that acquired the lock. If the thread that acquires this lock is terminated before releasing the lock state is undefined.
T
- The type of object that owns the lock.lockUpdater
- The AtomicLongFieldUpdater
used to control the lock state.owner
- The owner of the lock object.0
if the acquire was unsuccessful, otherwise an identifier that must be passed to a subsequent
call of releaseReentrantLock(AtomicLongFieldUpdater, long, Object)
.public static <T> boolean releaseReentrantLock(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> lockUpdater, long acquireId, T owner)
tryAcquireReentrantLock(AtomicLongFieldUpdater, Object)
.T
- The type of object that owns the lock.lockUpdater
- The AtomicLongFieldUpdater
used to control the lock state.acquireId
- The value returned from the previous call to
tryAcquireReentrantLock(AtomicLongFieldUpdater, Object)
.owner
- The owner of the lock object.true
if the lock was released, or releases a prior re-entrant acquire, and no other attempts were
made to acquire the lock while it was held. false
if the lock was released but another attempt was made
to acquire the lock before it was released.