Class CycleDetectingLock.CycleDetectingLockFactory.ReentrantCycleDetectingLock<ID>

    • Field Detail

      • lockImplementation

        private final java.util.concurrent.locks.Lock lockImplementation
        Underlying lock used for actual waiting when no potential deadlocks are detected.
      • userLockId

        private final ID userLockId
        User id for this lock.
      • lockOwnerThread

        private java.lang.Thread lockOwnerThread
        Thread that owns this lock. Nullable. Guarded by CycleDetectingLockFactory.this.
      • lockReentranceCount

        private int lockReentranceCount
        Number of times that thread owned this lock. Guarded by CycleDetectingLockFactory.this.
    • Method Detail

      • lockOrDetectPotentialLocksCycle

        public com.google.common.collect.ListMultimap<java.lang.Thread,​ID> lockOrDetectPotentialLocksCycle()
        Description copied from interface: CycleDetectingLock
        Takes a lock in a blocking fashion in case no potential deadlocks are detected. If the lock was successfully owned, returns an empty map indicating no detected potential deadlocks.

        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).

        Specified by:
        lockOrDetectPotentialLocksCycle in interface CycleDetectingLock<ID>
      • checkState

        void checkState()
                 throws java.lang.IllegalStateException
        Check consistency of an internal state.
        Throws:
        java.lang.IllegalStateException
      • detectPotentialLocksCycle

        private com.google.common.collect.ListMultimap<java.lang.Thread,​ID> detectPotentialLocksCycle()
        Algorithm to detect a potential lock cycle.

        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.

        See Also:
        CycleDetectingLock.lockOrDetectPotentialLocksCycle()
      • toString

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