@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 |
Constructor and Description |
---|
IdReadWriteLock() |
IdReadWriteLock(IdReadWriteLock.ReferenceType referenceType)
Constructor of IdReadWriteLock
|
Modifier and Type | Method and Description |
---|---|
ReentrantReadWriteLock |
getLock(T id)
Get the ReentrantReadWriteLock corresponding to the given id
|
IdReadWriteLock.ReferenceType |
getReferenceType() |
void |
waitForWaiters(T id,
int numWaiters) |
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 lockpublic void waitForWaiters(T id, int numWaiters) throws InterruptedException
InterruptedException
public IdReadWriteLock.ReferenceType getReferenceType()
Copyright © 2007–2019 Cloudera. All rights reserved.