Package org.apache.hadoop.hbase.util
Class KeyLocker<K>
java.lang.Object
org.apache.hadoop.hbase.util.KeyLocker<K>
A utility class to manage a set of locks. Each lock is identified by a String which serves as a
key. Typical usage is:
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();
}
}
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final WeakObjectPool<K,ReentrantLock> private static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionacquireLock(K key) Return a lock for the given key.acquireLocks(Set<? extends K> keys) Acquire locks for a set of keys.
-
Field Details
-
NB_CONCURRENT_LOCKS
- See Also:
-
lockPool
-
-
Constructor Details
-
KeyLocker
public KeyLocker()
-
-
Method Details
-
acquireLock
Return a lock for the given key. The lock is already locked. -
acquireLocks
Acquire locks for a set of keys. The keys will be sorted internally to avoid possible deadlock.- Throws:
ClassCastException- if the givenkeyscontains elements that are not mutually comparable
-