@InterfaceAudience.Private public class IdReadWriteLock 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 | Field and Description |
|---|---|
private WeakObjectPool<Long,ReentrantReadWriteLock> |
lockPool |
private static int |
NB_CONCURRENT_LOCKS |
| Constructor and Description |
|---|
IdReadWriteLock() |
| Modifier and Type | Method and Description |
|---|---|
private void |
gc() |
ReentrantReadWriteLock |
getLock(long id)
Get the ReentrantReadWriteLock corresponding to the given id
|
(package private) int |
purgeAndGetEntryPoolSize()
For testing
|
void |
waitForWaiters(long id,
int numWaiters) |
private static final int NB_CONCURRENT_LOCKS
private final WeakObjectPool<Long,ReentrantReadWriteLock> lockPool
public ReentrantReadWriteLock getLock(long id)
id - an arbitrary number to identify the lockint purgeAndGetEntryPoolSize()
private void gc()
public void waitForWaiters(long id,
int numWaiters)
throws InterruptedException
InterruptedExceptionCopyright © 2007–2019 The Apache Software Foundation. All rights reserved.