private void withLastLockAttemptFor(String lockPath, Consumer<LockAttempt> consumer) {
        Iterator<LockAttempt> lockAttemptIterator = lockAttemptsStack.descendingIterator();
        while (lockAttemptIterator.hasNext()) {
            LockAttempt lockAttempt = lockAttemptIterator.next();
            if (lockAttempt.getLockPath().equals(lockPath)) {
                consumer.accept(lockAttempt);
                return;
            }
        }

        logger.warning("Unable to find any lock attempts for " + lockPath);
    }
Tries to detect whether acquiring a given lock path would deadlock.

<p>Thread T0 will deadlock if it tries to acquire a lock on a path L1 held by T1,
and T1 is waiting on L2 held by T2, and so forth, and TN is waiting on L0 held by T0.</p>


<p>Since the underlying data structures are concurrently being modified (as an optimization,
no lock is taken for this calculation), a cycle may be detected not involving T0.</p>

<p>This method is a best-effort attempt at detecting deadlocks:  A deadlock may in fact be
resolved even though this method throws, if e.g. locks are released just after this
method.</p>
zkfacade/src/main/java/com/yahoo/vespa/curator/stats/ThreadLockStats.java