public class ExactReentrantSharedUseExclusiveUseLock extends java.lang.Object implements SharedUseExclusiveUseLock
Fully reentrant. We could still separate the shared and exclusive wait() sets for greater efficiency under circumstances of high contention, but it would require extra synchronizations even under low contention, so we'll leave this as is, and maybe write a different class that presumes large wait sets.
Because this class is reentrant, lock relinquishes can't be idempotent -- we have to keep track of precisely how many times the lock was acquired and then release. Clients therefore have to be very careful that every acquisition is matched by exactly one relinquish. The way to do this is to acquire locks immediately before a try lock, and putting the relinquish in the finally block. One should not attempt to acquire the locks within the try block, because if the lock acquisition is interrupted, the lock relinquish in the finally block will run without the lock acquisition having succeeded.
Constructor and Description |
---|
ExactReentrantSharedUseExclusiveUseLock() |
ExactReentrantSharedUseExclusiveUseLock(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
void |
acquireExclusive() |
void |
acquireShared() |
void |
relinquishExclusive() |
void |
relinquishShared() |
java.lang.String |
toString() |
public ExactReentrantSharedUseExclusiveUseLock(java.lang.String name)
public ExactReentrantSharedUseExclusiveUseLock()
public void acquireShared() throws java.lang.InterruptedException
acquireShared
in interface SharedUseExclusiveUseLock
java.lang.InterruptedException
public void relinquishShared()
relinquishShared
in interface SharedUseExclusiveUseLock
public void acquireExclusive() throws java.lang.InterruptedException
acquireExclusive
in interface SharedUseExclusiveUseLock
java.lang.InterruptedException
public void relinquishExclusive()
relinquishExclusive
in interface SharedUseExclusiveUseLock
public java.lang.String toString()
toString
in class java.lang.Object