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
-
Field Summary
Modifier and TypeFieldDescriptionprivate final ObjectPool<T,
ReentrantReadWriteLock> The pool to get entry from, entries are mapped byReference
and will be automatically garbage-collected by JVMprivate static final int
private final IdReadWriteLock.ReferenceType
-
Constructor Summary
ConstructorDescriptionIdReadWriteLock
(IdReadWriteLock.ReferenceType referenceType) Constructor of IdReadWriteLock -
Method Summary
Modifier and TypeMethodDescriptionprivate void
gc()
Get the ReentrantReadWriteLock corresponding to the given id(package private) int
For testingvoid
waitForWaiters
(T id, int numWaiters)
-
Field Details
-
NB_CONCURRENT_LOCKS
- See Also:
-
lockPool
The pool to get entry from, entries are mapped byReference
and 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.WEAK
by default. UseIdReadWriteLock.ReferenceType.SOFT
if 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
-