T
- the key typepublic class KeyedLocks<T> extends Object
Constructor and Description |
---|
KeyedLocks() |
Modifier and Type | Method and Description |
---|---|
void |
lock(T lockKey)
Acquires the lock for the given key.
|
boolean |
tryLock(T lockKey)
Acquires the lock for the given key only if it is not held by another thread at the time of invocation.
|
boolean |
tryLock(T lockKey,
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.
|
void |
unlock(T lockKey)
Attempts to release the lock for the given key.
|
public boolean tryLock(@Nonnull T lockKey, long timeout, TimeUnit unit)
ReentrantLock.tryLock(long, TimeUnit)
for more details.lockKey
- the key to locktimeout
- the time to wait for the lockunit
- the time unit of the timeout argumenttrue
if the lock was free and was acquired by the current thread, or the lock was already held
by the current thread, otherwise false
if the waiting time elapsed before the lock could be
acquired or the current thread was interrupted.public boolean tryLock(@Nonnull T lockKey)
ReentrantLock.tryLock()
for more details.lockKey
- the key to locktrue
if the lock was free and was acquired by the current thread, or the lock was already held
by the current thread, otherwise false
otherwisepublic void lock(@Nonnull T lockKey)
ReentrantLock.lock()
for more details.lockKey
- the key to lockpublic void unlock(@Nonnull T lockKey)
ReentrantLock.unlock()
for more details.lockKey
- the key to unlockIllegalMonitorStateException
- if the current thread does not hold this lockCopyright © 2019 OpenDaylight. All rights reserved.