@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()
Constructor and Description |
---|
IdReadWriteLock() |
Modifier and Type | Method and Description |
---|---|
ReentrantReadWriteLock |
getLock(long id)
Get the ReentrantReadWriteLock corresponding to the given id
|
void |
waitForWaiters(long id,
int numWaiters) |
public ReentrantReadWriteLock getLock(long id)
id
- an arbitrary number to identify the lockpublic void waitForWaiters(long id, int numWaiters) throws InterruptedException
InterruptedException