Class ExactReentrantSharedUseExclusiveUseLock
- java.lang.Object
-
- com.mchange.v2.lock.ExactReentrantSharedUseExclusiveUseLock
-
- All Implemented Interfaces:
SharedUseExclusiveUseLock
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 Summary
Constructors Constructor Description ExactReentrantSharedUseExclusiveUseLock()
ExactReentrantSharedUseExclusiveUseLock(java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
acquireExclusive()
void
acquireShared()
void
relinquishExclusive()
void
relinquishShared()
java.lang.String
toString()
-
-
-
Method Detail
-
acquireShared
public void acquireShared() throws java.lang.InterruptedException
- Specified by:
acquireShared
in interfaceSharedUseExclusiveUseLock
- Throws:
java.lang.InterruptedException
-
relinquishShared
public void relinquishShared()
- Specified by:
relinquishShared
in interfaceSharedUseExclusiveUseLock
-
acquireExclusive
public void acquireExclusive() throws java.lang.InterruptedException
- Specified by:
acquireExclusive
in interfaceSharedUseExclusiveUseLock
- Throws:
java.lang.InterruptedException
-
relinquishExclusive
public void relinquishExclusive()
- Specified by:
relinquishExclusive
in interfaceSharedUseExclusiveUseLock
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-