Deadlock deadlock = new Deadlock(); new Thread(deadlock, "RacingThread").start();
/** * Adds a 'deadlock detected' message to the log with a stack trace. */ private void reportDeadlock(Deadlock deadlock) { String msg = "Deadlock detected. All locks owned by thread " + deadlock.getCandidate().getName() + " will be suspended."; //$NON-NLS-1$ //$NON-NLS-2$ MultiStatus main = new MultiStatus(JobManager.PI_JOBS, JobManager.PLUGIN_ERROR, msg, new IllegalStateException()); Thread[] threads = deadlock.getThreads(); for (int i = 0; i < threads.length; i++) { Object[] ownedLocks = getOwnedLocks(threads[i]); Object waitLock = getWaitingLock(threads[i]); StringBuffer buf = new StringBuffer("Thread "); //$NON-NLS-1$ buf.append(threads[i].getName()); buf.append(" has locks: "); //$NON-NLS-1$ for (int j = 0; j < ownedLocks.length; j++) { buf.append(ownedLocks[j]); buf.append((j < ownedLocks.length - 1) ? ", " : " "); //$NON-NLS-1$ //$NON-NLS-2$ } buf.append("and is waiting for lock "); //$NON-NLS-1$ buf.append(waitLock); Status child = new Status(IStatus.ERROR, JobManager.PI_JOBS, JobManager.PLUGIN_ERROR, buf.toString(), null); main.add(child); } RuntimeLog.log(main); }
ISchedulingRule[] toSuspend = found.getLocks(); LockState[] suspended = new LockState[toSuspend.length]; for (int i = 0; i < toSuspend.length; i++) suspended[i] = LockState.suspend((OrderedLock) toSuspend[i]); synchronized (suspendedLocks) { Stack prevLocks = (Stack) suspendedLocks.get(found.getCandidate()); if (prevLocks == null) prevLocks = new Stack(); prevLocks.push(suspended); suspendedLocks.put(found.getCandidate(), prevLocks);
/** * The given thread could not get the given lock and is waiting for it. * Update the graph. */ Deadlock lockWaitStart(Thread client, ISchedulingRule lock) { setToWait(client, lock, false); int lockIndex = indexOf(lock, false); int[] temp = new int[lockThreads.size()]; //check if the addition of the waiting thread caused deadlock if (!checkWaitCycles(temp, lockIndex)) return null; //there is a deadlock in the graph Thread[] threads = getThreadsInDeadlock(client); //find a thread whose locks can be suspended to resolve the deadlock Thread candidate = resolutionCandidate(threads); ISchedulingRule[] locksToSuspend = realLocksForThread(candidate); Deadlock deadlock = new Deadlock(threads, locksToSuspend, candidate); reportDeadlock(deadlock); if (JobManager.DEBUG_DEADLOCK) throw new IllegalStateException("Deadlock detected. Caused by thread " + client.getName() + '.'); //$NON-NLS-1$ // Update the graph to indicate that the locks will now be suspended. // To indicate that the lock will be suspended, we set the thread to wait for the lock. // When the lock is forced to be released, the entry will be cleared. for (int i = 0; i < locksToSuspend.length; i++) setToWait(deadlock.getCandidate(), locksToSuspend[i], true); return deadlock; }
/** * The given thread could not get the given lock and is waiting for it. * Update the graph. */ Deadlock lockWaitStart(Thread client, ISchedulingRule lock) { setToWait(client, lock, false); int lockIndex = indexOf(lock, false); int[] temp = new int[lockThreads.size()]; //check if the addition of the waiting thread caused deadlock if (!checkWaitCycles(temp, lockIndex)) return null; //there is a deadlock in the graph Thread[] threads = getThreadsInDeadlock(client); //find a thread whose locks can be suspended to resolve the deadlock Thread candidate = resolutionCandidate(threads); ISchedulingRule[] locksToSuspend = realLocksForThread(candidate); Deadlock deadlock = new Deadlock(threads, locksToSuspend, candidate); reportDeadlock(deadlock); if (JobManager.DEBUG_DEADLOCK) throw new IllegalStateException("Deadlock detected. Caused by thread " + client.getName() + '.'); //$NON-NLS-1$ // Update the graph to indicate that the locks will now be suspended. // To indicate that the lock will be suspended, we set the thread to wait for the lock. // When the lock is forced to be released, the entry will be cleared. for (int i = 0; i < locksToSuspend.length; i++) setToWait(deadlock.getCandidate(), locksToSuspend[i], true); return deadlock; }
/** * The given thread could not get the given lock and is waiting for it. * Update the graph. */ Deadlock lockWaitStart(Thread client, ISchedulingRule lock) { setToWait(client, lock, false); int lockIndex = indexOf(lock, false); int[] temp = new int[lockThreads.size()]; //check if the addition of the waiting thread caused deadlock if (!checkWaitCycles(temp, lockIndex)) return null; //there is a deadlock in the graph Thread[] threads = getThreadsInDeadlock(client); //find a thread whose locks can be suspended to resolve the deadlock Thread candidate = resolutionCandidate(threads); ISchedulingRule[] locksToSuspend = realLocksForThread(candidate); Deadlock deadlock = new Deadlock(threads, locksToSuspend, candidate); reportDeadlock(deadlock); if (JobManager.DEBUG_DEADLOCK) throw new IllegalStateException("Deadlock detected. Caused by thread " + client.getName() + '.'); //$NON-NLS-1$ // Update the graph to indicate that the locks will now be suspended. // To indicate that the lock will be suspended, we set the thread to wait for the lock. // When the lock is forced to be released, the entry will be cleared. for (int i = 0; i < locksToSuspend.length; i++) setToWait(deadlock.getCandidate(), locksToSuspend[i], true); return deadlock; }
/** * Adds a 'deadlock detected' message to the log with a stack trace. */ private void reportDeadlock(Deadlock deadlock) { String msg = "Deadlock detected. All locks owned by thread " + deadlock.getCandidate().getName() + " will be suspended."; //$NON-NLS-1$ //$NON-NLS-2$ MultiStatus main = new MultiStatus(JobManager.PI_JOBS, JobManager.PLUGIN_ERROR, msg, new IllegalStateException()); Thread[] threads = deadlock.getThreads(); for (int i = 0; i < threads.length; i++) { Object[] ownedLocks = getOwnedLocks(threads[i]); Object waitLock = getWaitingLock(threads[i]); StringBuffer buf = new StringBuffer("Thread "); //$NON-NLS-1$ buf.append(threads[i].getName()); buf.append(" has locks: "); //$NON-NLS-1$ for (int j = 0; j < ownedLocks.length; j++) { buf.append(ownedLocks[j]); buf.append((j < ownedLocks.length - 1) ? ", " : " "); //$NON-NLS-1$ //$NON-NLS-2$ } buf.append("and is waiting for lock "); //$NON-NLS-1$ buf.append(waitLock); Status child = new Status(IStatus.ERROR, JobManager.PI_JOBS, JobManager.PLUGIN_ERROR, buf.toString(), null); main.add(child); } RuntimeLog.log(main); }
ISchedulingRule[] toSuspend = found.getLocks(); LockState[] suspended = new LockState[toSuspend.length]; for (int i = 0; i < toSuspend.length; i++) suspended[i] = LockState.suspend((OrderedLock) toSuspend[i]); synchronized (suspendedLocks) { Stack prevLocks = (Stack) suspendedLocks.get(found.getCandidate()); if (prevLocks == null) prevLocks = new Stack(); prevLocks.push(suspended); suspendedLocks.put(found.getCandidate(), prevLocks);
/** * The given thread could not get the given lock and is waiting for it. * Update the graph. */ Deadlock lockWaitStart(Thread client, ISchedulingRule lock) { setToWait(client, lock, false); int lockIndex = indexOf(lock, false); int[] temp = new int[lockThreads.size()]; //check if the addition of the waiting thread caused deadlock if (!checkWaitCycles(temp, lockIndex)) return null; //there is a deadlock in the graph Thread[] threads = getThreadsInDeadlock(client); Thread candidate = resolutionCandidate(threads); ISchedulingRule[] locksToSuspend = realLocksForThread(candidate); Deadlock deadlock = new Deadlock(threads, locksToSuspend, candidate); //find a thread whose locks can be suspended to resolve the deadlock if (JobManager.DEBUG_LOCKS) reportDeadlock(deadlock); if (JobManager.DEBUG_DEADLOCK) throw new IllegalStateException("Deadlock detected. Caused by thread " + client.getName() + '.'); //$NON-NLS-1$ // Update the graph to indicate that the locks will now be suspended. // To indicate that the lock will be suspended, we set the thread to wait for the lock. // When the lock is forced to be released, the entry will be cleared. for (int i = 0; i < locksToSuspend.length; i++) setToWait(deadlock.getCandidate(), locksToSuspend[i], true); return deadlock; }
/** * Adds a 'deadlock detected' message to the log with a stack trace. */ private void reportDeadlock(Deadlock deadlock) { String msg = "Deadlock detected. All locks owned by thread " + deadlock.getCandidate().getName() + " will be suspended."; //$NON-NLS-1$ //$NON-NLS-2$ MultiStatus main = new MultiStatus(JobManager.PI_JOBS, JobManager.PLUGIN_ERROR, msg, new IllegalStateException()); Thread[] threads = deadlock.getThreads(); for (int i = 0; i < threads.length; i++) { Object[] ownedLocks = getOwnedLocks(threads[i]); Object waitLock = getWaitingLock(threads[i]); StringBuffer buf = new StringBuffer("Thread "); //$NON-NLS-1$ buf.append(threads[i].getName()); buf.append(" has locks: "); //$NON-NLS-1$ for (int j = 0; j < ownedLocks.length; j++) { buf.append(ownedLocks[j]); buf.append((j < ownedLocks.length - 1) ? ", " : " "); //$NON-NLS-1$ //$NON-NLS-2$ } buf.append("and is waiting for lock "); //$NON-NLS-1$ buf.append(waitLock); Status child = new Status(IStatus.ERROR, JobManager.PI_JOBS, JobManager.PLUGIN_ERROR, buf.toString(), null); main.add(child); } RuntimeLog.log(main); }
ISchedulingRule[] toSuspend = found.getLocks(); LockState[] suspended = new LockState[toSuspend.length]; for (int i = 0; i < toSuspend.length; i++) suspended[i] = LockState.suspend((OrderedLock) toSuspend[i]); synchronized (suspendedLocks) { Stack<LockState[]> prevLocks = suspendedLocks.get(found.getCandidate()); if (prevLocks == null) prevLocks = new Stack<>(); prevLocks.push(suspended); suspendedLocks.put(found.getCandidate(), prevLocks);
/** * Adds a 'deadlock detected' message to the log with a stack trace. */ private void reportDeadlock(Deadlock deadlock) { String msg = "Deadlock detected. All locks owned by thread " + deadlock.getCandidate().getName() + " will be suspended."; //$NON-NLS-1$ //$NON-NLS-2$ MultiStatus main = new MultiStatus(JobManager.PI_JOBS, JobManager.PLUGIN_ERROR, msg, new IllegalStateException()); Thread[] threads = deadlock.getThreads(); for (int i = 0; i < threads.length; i++) { Object[] ownedLocks = getOwnedLocks(threads[i]); Object waitLock = getWaitingLock(threads[i]); StringBuffer buf = new StringBuffer("Thread "); //$NON-NLS-1$ buf.append(threads[i].getName()); buf.append(" has locks: "); //$NON-NLS-1$ for (int j = 0; j < ownedLocks.length; j++) { buf.append(ownedLocks[j]); buf.append((j < ownedLocks.length - 1) ? ", " : " "); //$NON-NLS-1$ //$NON-NLS-2$ } buf.append("and is waiting for lock "); //$NON-NLS-1$ buf.append(waitLock); Status child = new Status(IStatus.ERROR, JobManager.PI_JOBS, JobManager.PLUGIN_ERROR, buf.toString(), null); main.add(child); } RuntimeLog.log(main); }
ISchedulingRule[] toSuspend = found.getLocks(); LockState[] suspended = new LockState[toSuspend.length]; for (int i = 0; i < toSuspend.length; i++) suspended[i] = LockState.suspend((OrderedLock) toSuspend[i]); synchronized (suspendedLocks) { Stack<LockState[]> prevLocks = suspendedLocks.get(found.getCandidate()); if (prevLocks == null) prevLocks = new Stack<LockState[]>(); prevLocks.push(suspended); suspendedLocks.put(found.getCandidate(), prevLocks);