static class CycleDetectingLock.CycleDetectingLockFactory.ReentrantCycleDetectingLock<ID> extends java.lang.Object implements CycleDetectingLock<ID>
CycleDetectingLock
.CycleDetectingLock.CycleDetectingLockFactory<ID>
Modifier and Type | Field and Description |
---|---|
private CycleDetectingLock.CycleDetectingLockFactory<ID> |
lockFactory
Factory that was used to create this lock.
|
private java.util.concurrent.locks.Lock |
lockImplementation
Underlying lock used for actual waiting when no potential deadlocks are detected.
|
private java.lang.Thread |
lockOwnerThread
Thread that owns this lock.
|
private int |
lockReentranceCount
Number of times that thread owned this lock.
|
private ID |
userLockId
User id for this lock.
|
Constructor and Description |
---|
ReentrantCycleDetectingLock(CycleDetectingLock.CycleDetectingLockFactory<ID> lockFactory,
ID userLockId,
java.util.concurrent.locks.Lock lockImplementation) |
Modifier and Type | Method and Description |
---|---|
private CycleDetectingLock.CycleDetectingLockFactory.ReentrantCycleDetectingLock<?> |
addAllLockIdsAfter(java.lang.Thread thread,
CycleDetectingLock.CycleDetectingLockFactory.ReentrantCycleDetectingLock<?> lock,
com.google.common.collect.ListMultimap<java.lang.Thread,ID> potentialLocksCycle)
Adds all locks held by the given thread that are after the given lock and then returns the
lock the thread is currently waiting on, if any
|
(package private) void |
checkState()
Check consistency of an internal state.
|
private com.google.common.collect.ListMultimap<java.lang.Thread,ID> |
detectPotentialLocksCycle()
Algorithm to detect a potential lock cycle.
|
com.google.common.collect.ListMultimap<java.lang.Thread,ID> |
lockOrDetectPotentialLocksCycle()
Takes a lock in a blocking fashion in case no potential deadlocks are detected.
|
java.lang.String |
toString() |
void |
unlock()
Unlocks previously locked lock.
|
private final java.util.concurrent.locks.Lock lockImplementation
private final ID userLockId
private final CycleDetectingLock.CycleDetectingLockFactory<ID> lockFactory
private java.lang.Thread lockOwnerThread
CycleDetectingLockFactory.this
.private int lockReentranceCount
CycleDetectingLockFactory.this
.ReentrantCycleDetectingLock(CycleDetectingLock.CycleDetectingLockFactory<ID> lockFactory, ID userLockId, java.util.concurrent.locks.Lock lockImplementation)
public com.google.common.collect.ListMultimap<java.lang.Thread,ID> lockOrDetectPotentialLocksCycle()
CycleDetectingLock
Otherwise, a map indicating threads involved in a potential deadlock are returned. Map is ordered by dependency cycle and lists locks for each thread that are part of the loop in order, the last lock in the list is the one that the thread is currently waiting for. Returned map is created atomically.
In case no cycle is detected performance is O(threads creating singletons), in case cycle is detected performance is O(singleton locks).
lockOrDetectPotentialLocksCycle
in interface CycleDetectingLock<ID>
public void unlock()
CycleDetectingLock
unlock
in interface CycleDetectingLock<ID>
void checkState() throws java.lang.IllegalStateException
java.lang.IllegalStateException
private com.google.common.collect.ListMultimap<java.lang.Thread,ID> detectPotentialLocksCycle()
For lock's thread owner check which lock is it trying to take. Repeat recursively. When current thread is found a potential cycle is detected.
private CycleDetectingLock.CycleDetectingLockFactory.ReentrantCycleDetectingLock<?> addAllLockIdsAfter(java.lang.Thread thread, CycleDetectingLock.CycleDetectingLockFactory.ReentrantCycleDetectingLock<?> lock, com.google.common.collect.ListMultimap<java.lang.Thread,ID> potentialLocksCycle)
public java.lang.String toString()
toString
in class java.lang.Object