Top Description Fields Constructors Methods
com.mchange.v2.lock

public Class ExactReentrantSharedUseExclusiveUseLock

extends Object
implements SharedUseExclusiveUseLock
Class Inheritance
All Implemented Interfaces
com.mchange.v2.lock.SharedUseExclusiveUseLock
Imports
java.util.*

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.

Field Summary

Modifier and TypeField and Description
pack-priv Thread
pack-priv List<E>
pack-priv int
pack-priv int
pack-priv String
pack-priv Set<E>
pack-priv Set<E>

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
public synchronized void
private boolean
private boolean
public synchronized void
public synchronized void
pack-priv void
status(String afterMethod)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

activeExclusiveback to summary
pack-priv Thread activeExclusive
activeSharedback to summary
pack-priv List<E> activeShared
exclusive_exclusive_reentriesback to summary
pack-priv int exclusive_exclusive_reentries
exclusive_shared_reentriesback to summary
pack-priv int exclusive_shared_reentries
nameback to summary
pack-priv String name
waitingExclusiveback to summary
pack-priv Set<E> waitingExclusive
waitingSharedback to summary
pack-priv Set<E> waitingShared

Constructor Detail

ExactReentrantSharedUseExclusiveUseLockback to summary
public ExactReentrantSharedUseExclusiveUseLock(String name)
ExactReentrantSharedUseExclusiveUseLockback to summary
public ExactReentrantSharedUseExclusiveUseLock()

Method Detail

acquireExclusiveback to summary
public synchronized void acquireExclusive() throws InterruptedException

Implements com.mchange.v2.lock.SharedUseExclusiveUseLock.acquireExclusive.

acquireSharedback to summary
public synchronized void acquireShared() throws InterruptedException

Implements com.mchange.v2.lock.SharedUseExclusiveUseLock.acquireShared.

okayForExclusiveback to summary
private boolean okayForExclusive(Thread t)
okayForSharedback to summary
private boolean okayForShared()
relinquishExclusiveback to summary
public synchronized void relinquishExclusive()

Implements com.mchange.v2.lock.SharedUseExclusiveUseLock.relinquishExclusive.

relinquishSharedback to summary
public synchronized void relinquishShared()

Implements com.mchange.v2.lock.SharedUseExclusiveUseLock.relinquishShared.

statusback to summary
pack-priv void status(String afterMethod)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object