@InterfaceAudience.Private public class KeyLocker<K> extends Object
class Example { private final static KeyLocker<String> locker = new Locker<String>(); public void foo(String s){ Lock lock = locker.acquireLock(s); try { // whatever }finally{ lock.unlock(); } } }
Modifier and Type | Field and Description |
---|---|
private WeakObjectPool<K,ReentrantLock> |
lockPool |
private static int |
NB_CONCURRENT_LOCKS |
Constructor and Description |
---|
KeyLocker() |
Modifier and Type | Method and Description |
---|---|
ReentrantLock |
acquireLock(K key)
Return a lock for the given key.
|
Map<K,Lock> |
acquireLocks(Set<? extends K> keys)
Acquire locks for a set of keys.
|
private static final int NB_CONCURRENT_LOCKS
private final WeakObjectPool<K,ReentrantLock> lockPool
public KeyLocker()
public ReentrantLock acquireLock(K key)
key
- public Map<K,Lock> acquireLocks(Set<? extends K> keys)
ClassCastException
- if the given keys
contains elements that are not mutually comparableCopyright © 2007–2019 The Apache Software Foundation. All rights reserved.