@InterfaceAudience.Private public class IdReadWriteLock<T> extends Object
ReentrantReadWriteLock lock = idReadWriteLock.getLock(id); try { lock.readLock().lock(); // User code. } finally { lock.readLock().unlock(); }For write lock, use lock.writeLock()
Modifier and Type | Class and Description |
---|---|
static class |
IdReadWriteLock.ReferenceType |
Modifier and Type | Field and Description |
---|---|
private ObjectPool<T,ReentrantReadWriteLock> |
lockPool
The pool to get entry from, entries are mapped by
Reference and will be automatically
garbage-collected by JVM |
private static int |
NB_CONCURRENT_LOCKS |
private IdReadWriteLock.ReferenceType |
refType |
Constructor and Description |
---|
IdReadWriteLock() |
IdReadWriteLock(IdReadWriteLock.ReferenceType referenceType)
Constructor of IdReadWriteLock
|
Modifier and Type | Method and Description |
---|---|
private void |
gc() |
ReentrantReadWriteLock |
getLock(T id)
Get the ReentrantReadWriteLock corresponding to the given id
|
IdReadWriteLock.ReferenceType |
getReferenceType() |
(package private) int |
purgeAndGetEntryPoolSize()
For testing
|
void |
waitForWaiters(T id,
int numWaiters) |
private static final int NB_CONCURRENT_LOCKS
private final ObjectPool<T,ReentrantReadWriteLock> lockPool
Reference
and will be automatically
garbage-collected by JVMprivate final IdReadWriteLock.ReferenceType refType
public IdReadWriteLock()
public IdReadWriteLock(IdReadWriteLock.ReferenceType referenceType)
referenceType
- type of the reference used in lock pool, IdReadWriteLock.ReferenceType.WEAK
by
default. Use IdReadWriteLock.ReferenceType.SOFT
if the key set is limited and the locks will
be reused with a high frequencypublic ReentrantReadWriteLock getLock(T id)
id
- an arbitrary number to identify the lockint purgeAndGetEntryPoolSize()
private void gc()
public void waitForWaiters(T id, int numWaiters) throws InterruptedException
InterruptedException
public IdReadWriteLock.ReferenceType getReferenceType()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.