com.mchange.v2.lock
Class ExactReentrantSharedUseExclusiveUseLock

java.lang.Object
  extended by 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
ExactReentrantSharedUseExclusiveUseLock()
           
ExactReentrantSharedUseExclusiveUseLock(java.lang.String name)
           
 
Method Summary
 void acquireExclusive()
           
 void acquireShared()
           
 void relinquishExclusive()
           
 void relinquishShared()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExactReentrantSharedUseExclusiveUseLock

public ExactReentrantSharedUseExclusiveUseLock(java.lang.String name)

ExactReentrantSharedUseExclusiveUseLock

public ExactReentrantSharedUseExclusiveUseLock()
Method Detail

acquireShared

public void acquireShared()
                   throws java.lang.InterruptedException
Specified by:
acquireShared in interface SharedUseExclusiveUseLock
Throws:
java.lang.InterruptedException

relinquishShared

public void relinquishShared()
Specified by:
relinquishShared in interface SharedUseExclusiveUseLock

acquireExclusive

public void acquireExclusive()
                      throws java.lang.InterruptedException
Specified by:
acquireExclusive in interface SharedUseExclusiveUseLock
Throws:
java.lang.InterruptedException

relinquishExclusive

public void relinquishExclusive()
Specified by:
relinquishExclusive in interface SharedUseExclusiveUseLock

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object