Package org.apache.hadoop.hbase.util
Class IdReadWriteLock<T>
java.lang.Object
org.apache.hadoop.hbase.util.IdReadWriteLock<T>
Allows multiple concurrent clients to lock on a numeric id with ReentrantReadWriteLock. The
intended usage for read lock is as follows:
ReentrantReadWriteLock lock = idReadWriteLock.getLock(id);
try {
lock.readLock().lock();
// User code.
} finally {
lock.readLock().unlock();
}
For write lock, use lock.writeLock()-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ObjectPool<T,ReentrantReadWriteLock> The pool to get entry from, entries are mapped byReferenceand will be automatically garbage-collected by JVMprivate static final intprivate final IdReadWriteLock.ReferenceType -
Constructor Summary
ConstructorsConstructorDescriptionIdReadWriteLock(IdReadWriteLock.ReferenceType referenceType) Constructor of IdReadWriteLock -
Method Summary
Modifier and TypeMethodDescriptionprivate voidgc()Get the ReentrantReadWriteLock corresponding to the given id(package private) intFor testingvoidwaitForWaiters(T id, int numWaiters)
-
Field Details
-
NB_CONCURRENT_LOCKS
- See Also:
-
lockPool
The pool to get entry from, entries are mapped byReferenceand will be automatically garbage-collected by JVM -
refType
-
-
Constructor Details
-
IdReadWriteLock
public IdReadWriteLock() -
IdReadWriteLock
Constructor of IdReadWriteLock- Parameters:
referenceType- type of the reference used in lock pool,IdReadWriteLock.ReferenceType.WEAKby default. UseIdReadWriteLock.ReferenceType.SOFTif the key set is limited and the locks will be reused with a high frequency
-
-
Method Details
-
getLock
Get the ReentrantReadWriteLock corresponding to the given id- Parameters:
id- an arbitrary number to identify the lock
-
purgeAndGetEntryPoolSize
int purgeAndGetEntryPoolSize()For testing -
gc
-
waitForWaiters
- Throws:
InterruptedException
-
getReferenceType
-