public LinkedList<Dependency> findCycle() {

    Set<Object> unvisited = new HashSet<>(vertices.keySet());
    Set<Object> finished = new HashSet<>(vertices.size());

    while (unvisited.size() > 0) {
      Object start = unvisited.iterator().next();
      CycleHolder cycle = new CycleHolder();

      boolean foundCycle = visitCycle(start, unvisited, finished, cycle, 0);
      if (foundCycle) {
        return cycle.cycle;
      }
    }

    return null;
  }
Find a cycle in the graph, if one exists.

This method works by starting at any vertex and doing a depth first search. If it ever
encounters a vertex that is currently in the middle of the search (as opposed to a vertex whose
dependencies have been completely analyzed), then it returns the chain that starts from our
start vertex and includes the cycle.
geode-core/src/main/java/org/apache/geode/distributed/internal/deadlock/DependencyGraph.java