/** * Recursively check if any of the threads that prevent the current thread from running * are actually deadlocked with the current thread. * Add the threads that form deadlock to the deadlockedThreads list. */ private boolean addCycleThreads(ArrayList<Thread> deadlockedThreads, Thread next) { //get the thread that block the given thread from running Thread[] blocking = blockingThreads(next); //if the thread is not blocked by other threads, then it is not part of a deadlock if (blocking.length == 0) return false; boolean inCycle = false; for (int i = 0; i < blocking.length; i++) { //if we have already visited the given thread, then we found a cycle if (deadlockedThreads.contains(blocking[i])) { inCycle = true; } else { //otherwise, add the thread to our list and recurse deeper deadlockedThreads.add(blocking[i]); //if the thread is not part of a cycle, remove it from the list if (addCycleThreads(deadlockedThreads, blocking[i])) inCycle = true; else deadlockedThreads.remove(blocking[i]); } } return inCycle; }
/** * Recursively check if any of the threads that prevent the current thread from running * are actually deadlocked with the current thread. * Add the threads that form deadlock to the deadlockedThreads list. */ private boolean addCycleThreads(ArrayList deadlockedThreads, Thread next) { //get the thread that block the given thread from running Thread[] blocking = blockingThreads(next); //if the thread is not blocked by other threads, then it is not part of a deadlock if (blocking.length == 0) return false; boolean inCycle = false; for (int i = 0; i < blocking.length; i++) { //if we have already visited the given thread, then we found a cycle if (deadlockedThreads.contains(blocking[i])) { inCycle = true; } else { //otherwise, add the thread to our list and recurse deeper deadlockedThreads.add(blocking[i]); //if the thread is not part of a cycle, remove it from the list if (addCycleThreads(deadlockedThreads, blocking[i])) inCycle = true; else deadlockedThreads.remove(blocking[i]); } } return inCycle; }
/** * Recursively check if any of the threads that prevent the current thread from running * are actually deadlocked with the current thread. * Add the threads that form deadlock to the deadlockedThreads list. */ private boolean addCycleThreads(ArrayList<Thread> deadlockedThreads, Thread next) { //get the thread that block the given thread from running Thread[] blocking = blockingThreads(next); //if the thread is not blocked by other threads, then it is not part of a deadlock if (blocking.length == 0) return false; boolean inCycle = false; for (int i = 0; i < blocking.length; i++) { //if we have already visited the given thread, then we found a cycle if (deadlockedThreads.contains(blocking[i])) { inCycle = true; } else { //otherwise, add the thread to our list and recurse deeper deadlockedThreads.add(blocking[i]); //if the thread is not part of a cycle, remove it from the list if (addCycleThreads(deadlockedThreads, blocking[i])) inCycle = true; else deadlockedThreads.remove(blocking[i]); } } return inCycle; }
/** * Recursively check if any of the threads that prevent the current thread from running * are actually deadlocked with the current thread. * Add the threads that form deadlock to the deadlockedThreads list. */ private boolean addCycleThreads(ArrayList deadlockedThreads, Thread next) { //get the thread that block the given thread from running Thread[] blocking = blockingThreads(next); //if the thread is not blocked by other threads, then it is not part of a deadlock if (blocking.length == 0) return false; boolean inCycle = false; for (int i = 0; i < blocking.length; i++) { //if we have already visited the given thread, then we found a cycle if (deadlockedThreads.contains(blocking[i])) { inCycle = true; } else { //otherwise, add the thread to our list and recurse deeper deadlockedThreads.add(blocking[i]); //if the thread is not part of a cycle, remove it from the list if (addCycleThreads(deadlockedThreads, blocking[i])) inCycle = true; else deadlockedThreads.remove(blocking[i]); } } return inCycle; }