T
- the name type, required to be effectively immutable where T.hashCode() and T.equals() is concernedpublic final class NamedLocks<T> extends Object
Example of use of lock():
NamedLocks<String> locks; String lockName; try (Acquired lock = locks.Acquire(lockName)) { // locked region } // lock released
Example of use of tryLock():
NamedLocks<String> locks; String lockName; try (AcquireResult lock = locks.tryAcquire(lockName)) { // maybe locked region if (lock.wasAcquired()) { // locked region } else { // unlocked region } }); // lock released
Constructor and Description |
---|
NamedLocks() |
Modifier and Type | Method and Description |
---|---|
NamedSimpleReentrantLock.Acquired |
acquire(T lockKey)
Acquires the lock for the given key.
|
NamedSimpleReentrantLock<T> |
getLock(T lockKey) |
NamedSimpleReentrantLock.AcquireResult |
tryAcquire(T lockName)
Acquires the lock for the given key only if it is not held by another thread at the time of invocation.
|
NamedSimpleReentrantLock.AcquireResult |
tryAcquire(T lockName,
long timeout,
TimeUnit unit)
Tries to acquire the lock for the given key if it is not held by another thread within the given waiting time.
|
public NamedSimpleReentrantLock.AcquireResult tryAcquire(T lockName, long timeout, TimeUnit unit)
ReentrantLock.tryLock(long, TimeUnit)
for more details.lockName
- the key to locktimeout
- the time to wait for the lockunit
- the time unit of the timeout argumentNamedSimpleReentrantLock.AcquireResult.wasAcquired()
will return true. If it reports false, the locking attempt failed,
either due to lock time expiring or the thread being interrupted while waiting.public NamedSimpleReentrantLock.AcquireResult tryAcquire(T lockName)
ReentrantLock.tryLock()
for more details.lockName
- the key to lockNamedSimpleReentrantLock.AcquireResult.wasAcquired()
will return true. If it reports false, the locking attempt failed,
because another thread is currently holding the lock.public NamedSimpleReentrantLock.Acquired acquire(T lockKey)
ReentrantLock.lock()
for more details.lockKey
- the key to lockpublic NamedSimpleReentrantLock<T> getLock(T lockKey)
Copyright © 2019 OpenDaylight. All rights reserved.