Class ConcurrentLockSet
- All Implemented Interfaces:
LockTable
Lockables to LockControl objects.
A LockControl contains information about the locks held on a Lockable.
MT - Mutable : All public methods of this class, except addWaiters, are
thread safe. addWaiters can only be called from the thread which performs
deadlock detection. Only one thread can perform deadlock detection at a
time.
The class creates ActiveLock and LockControl objects.
LockControl objects are never passed out of this class, All the methods of
LockControl are called while holding a ReentrantLock associated with the
Lockable controlled by the LockControl, thus providing the
single threading that LockControl required.
Methods of Lockables are only called by this class or LockControl, and
always while holding the corresponding ReentrantLock, thus providing the
single threading that Lockable requires.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classClass representing an entry in the lock table. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicIntegerprivate intTimeout for deadlocks, in ms.private booleanprivate final AbstractPoolprivate final ConcurrentHashMap<Lockable, ConcurrentLockSet.Entry> Hash table which mapsLockableobjects toLocks.private ArrayList<ConcurrentLockSet.Entry> List containing all entries seen by the last call toaddWaiters().private int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddWaiters(Map<Object, Object> waiters) Add all waiters in this lock table to aMapobject.booleanCheck whether anyone is blocked.private Object[]checkDeadlock(ConcurrentLockSet.Entry entry, ActiveLock waitingLock, byte wakeupReason) Check whether there is a deadlock.private ConcurrentLockSet.EntryGet an entry from the lock table.intGet the wait timeout in milliseconds.lockObject(CompatibilitySpace compatibilitySpace, Lockable ref, Object qualifier, int timeout) Lock an object within a specific compatibility space.voidDecrease blockCount by one.voidIncrease blockCount by one.voidsetDeadlockTimeout(int timeout) Set the deadlock timeout.voidsetDeadlockTrace(boolean val) Enable or disable tracing of deadlocks.voidsetWaitTimeout(int timeout) Set the wait timeout.make a shallow clone of myself and my lock controlsprivate StringvoidUnlock an object, previously locked by lockObject().private voidunlock(ConcurrentLockSet.Entry entry, Latch item, int unlockCount) Unlock an object, previously locked by lockObject().unlockReference(CompatibilitySpace space, Lockable ref, Object qualifier, Map group) Unlock an object once if it is present in the specified group.booleanzeroDurationLockObject(CompatibilitySpace space, Lockable ref, Object qualifier, int timeout) Lock an object and release the lock immediately.
-
Field Details
-
factory
-
locks
Hash table which mapsLockableobjects toLocks. -
seenByDeadlockDetection
List containing all entries seen by the last call toaddWaiters(). Makes it possible for the deadlock detection thread to lock all the entries it has visited until it has finished. This prevents false deadlocks from being reported (because all observed waiters must still be waiting when the deadlock detection has completed). -
deadlockTimeout
private int deadlockTimeoutTimeout for deadlocks, in ms.
MT - immutable -
waitTimeout
private int waitTimeout -
deadlockTrace
private boolean deadlockTrace -
blockCount
-
-
Constructor Details
-
ConcurrentLockSet
ConcurrentLockSet(AbstractPool factory)
-
-
Method Details
-
getEntry
Get an entry from the lock table. If no entry exists for theLockable, insert an entry. The returned entry will be locked and is guaranteed to still be present in the table.- Parameters:
ref- theLockablewhose entry to return- Returns:
- the entry for the
Lockable, locked for exclusive access
-
checkDeadlock
private Object[] checkDeadlock(ConcurrentLockSet.Entry entry, ActiveLock waitingLock, byte wakeupReason) Check whether there is a deadlock. Make sure that only one thread enters deadlock detection at a time.- Parameters:
entry- the entry in the lock table for the lock request that triggered deadlock detectionwaitingLock- the waiting lockwakeupReason- the reason for waking up the waiter- Returns:
- an object describing the deadlock
-
lockObject
public Lock lockObject(CompatibilitySpace compatibilitySpace, Lockable ref, Object qualifier, int timeout) throws StandardException Lock an object within a specific compatibility space.- Specified by:
lockObjectin interfaceLockTable- Parameters:
compatibilitySpace- Compatibility space.ref- Lockable reference.qualifier- Qualifier.timeout- Timeout in milli-seconds- Returns:
- Object that represents the lock.
- Throws:
StandardException- Standard Derby policy.
-
unlock
Unlock an object, previously locked by lockObject(). If unlockCOunt is not zero then the lock will be unlocked that many times, otherwise the unlock count is taken from item. -
unlock
Unlock an object, previously locked by lockObject().- Parameters:
entry- the entry in which the lock is contained (the current thread must have locked the entry)item- the item to unlockunlockCount- the number of times to unlock the item (if zero, take the unlock count from item)
-
unlockReference
Unlock an object once if it is present in the specified group. Also remove the object from the group.- Specified by:
unlockReferencein interfaceLockTable- Parameters:
space- the compatibility spaceref- a reference to the locked objectqualifier- qualifier of the lockgroup- a map representing the locks in a group- Returns:
- the corresponding lock in the group map, or
nullif the object was not unlocked
-
zeroDurationLockObject
public boolean zeroDurationLockObject(CompatibilitySpace space, Lockable ref, Object qualifier, int timeout) throws StandardException Lock an object and release the lock immediately. Equivalent toLock lock = lockTable.lockObject(space, ref, qualifier, timeout); lockTable.unlock(lock, 1);
except that the implementation might be more efficient.- Specified by:
zeroDurationLockObjectin interfaceLockTable- Parameters:
space- the compatibility spaceref- a reference to the locked objectqualifier- qualifier of the locktimeout- maximum time to wait in milliseconds (C_LockFactory.NO_WAITmeans don't wait)- Returns:
trueif the object was locked, orfalseif the object couldn't be locked immediately and timeout wasNO_WAITorLockOwnerhad thenoWaitflag set- Throws:
StandardException- if the lock could not be obtained
-
setDeadlockTimeout
public void setDeadlockTimeout(int timeout) Set the deadlock timeout.- Specified by:
setDeadlockTimeoutin interfaceLockTable- Parameters:
timeout- deadlock timeout in milliseconds
-
setWaitTimeout
public void setWaitTimeout(int timeout) Set the wait timeout.- Specified by:
setWaitTimeoutin interfaceLockTable- Parameters:
timeout- wait timeout in milliseconds
-
getWaitTimeout
public int getWaitTimeout()Get the wait timeout in milliseconds.- Specified by:
getWaitTimeoutin interfaceLockTable
-
setDeadlockTrace
public void setDeadlockTrace(boolean val) Description copied from interface:LockTableEnable or disable tracing of deadlocks.- Specified by:
setDeadlockTracein interfaceLockTable- Parameters:
val-trueenables tracing,falsedisables tracing
-
toDebugString
-
addWaiters
Add all waiters in this lock table to aMapobject. This method can only be called by the thread that is currently performing deadlock detection. All entries that are visited in the lock table will be locked when this method returns. The entries that have been seen and locked will be unlocked after the deadlock detection has finished.- Specified by:
addWaitersin interfaceLockTable- Parameters:
waiters- the map to add the waiters to- See Also:
-
shallowClone
make a shallow clone of myself and my lock controls- Specified by:
shallowClonein interfaceLockTable- Returns:
- a shallow clone of the lock table
-
oneMoreWaiter
public void oneMoreWaiter()Increase blockCount by one.- Specified by:
oneMoreWaiterin interfaceLockTable
-
oneLessWaiter
public void oneLessWaiter()Decrease blockCount by one.- Specified by:
oneLessWaiterin interfaceLockTable
-
anyoneBlocked
public boolean anyoneBlocked()Check whether anyone is blocked.- Specified by:
anyoneBlockedin interfaceLockTable- Returns:
trueif someone is blocked,falseotherwise
-