@Override public void backgroundProcess() { super.backgroundProcess(); long thresholdInMillis = threshold * 1000; // Check monitored threads, being careful that the request might have // completed by the time we examine it for (MonitoredThread monitoredThread : activeThreads.values()) { long activeTime = monitoredThread.getActiveTimeInMillis(); if (activeTime >= thresholdInMillis && monitoredThread.markAsStuckIfStillRunning()) { int numStuckThreads = stuckCount.incrementAndGet(); notifyStuckThreadDetected(monitoredThread, activeTime, numStuckThreads); } } // Check if any threads previously reported as stuck, have finished. for (CompletedStuckThread completedStuckThread = completedStuckThreadsQueue.poll(); completedStuckThread != null; completedStuckThread = completedStuckThreadsQueue.poll()) { int numStuckThreads = stuckCount.decrementAndGet(); notifyStuckThreadCompleted(completedStuckThread, numStuckThreads); } }
@Override public void backgroundProcess() { super.backgroundProcess(); long thresholdInMillis = threshold * 1000; // Check monitored threads, being careful that the request might have // completed by the time we examine it for (MonitoredThread monitoredThread : activeThreads.values()) { long activeTime = monitoredThread.getActiveTimeInMillis(); if (activeTime >= thresholdInMillis && monitoredThread.markAsStuckIfStillRunning()) { int numStuckThreads = stuckCount.incrementAndGet(); notifyStuckThreadDetected(monitoredThread, activeTime, numStuckThreads); } } // Check if any threads previously reported as stuck, have finished. for (CompletedStuckThread completedStuckThread = completedStuckThreadsQueue.poll(); completedStuckThread != null; completedStuckThread = completedStuckThreadsQueue.poll()) { int numStuckThreads = stuckCount.decrementAndGet(); notifyStuckThreadCompleted(completedStuckThread, numStuckThreads); } }
@Override public void backgroundProcess() { super.backgroundProcess(); long thresholdInMillis = threshold * 1000; // Check monitored threads, being careful that the request might have // completed by the time we examine it for (MonitoredThread monitoredThread : activeThreads.values()) { long activeTime = monitoredThread.getActiveTimeInMillis(); if (activeTime >= thresholdInMillis && monitoredThread.markAsStuckIfStillRunning()) { int numStuckThreads = stuckCount.incrementAndGet(); notifyStuckThreadDetected(monitoredThread, activeTime, numStuckThreads); } } // Check if any threads previously reported as stuck, have finished. for (CompletedStuckThread completedStuckThread = completedStuckThreadsQueue.poll(); completedStuckThread != null; completedStuckThread = completedStuckThreadsQueue.poll()) { int numStuckThreads = stuckCount.decrementAndGet(); notifyStuckThreadCompleted(completedStuckThread, numStuckThreads); } }
monitoredThread.getActiveTimeInMillis()));
completedStuckThreadsQueue.add( new CompletedStuckThread(monitoredThread.getThread(), monitoredThread.getActiveTimeInMillis()));
completedStuckThreadsQueue.add( new CompletedStuckThread(monitoredThread.getThread(), monitoredThread.getActiveTimeInMillis()));
completedStuckThreadsQueue.add( new CompletedStuckThread(monitoredThread.getThread(), monitoredThread.getActiveTimeInMillis()));
public boolean interruptIfStuck(long interruptThreadThreshold) { if (!isMarkedAsStuck() || interruptionSemaphore == null || !this.interruptionSemaphore.tryAcquire()) { // if the semaphore is already acquired, it means that the // request thread got unstuck before we interrupted it return false; } try { if (log.isWarnEnabled()) { String msg = sm.getString( "stuckThreadDetectionValve.notifyStuckThreadInterrupted", this.getThread().getName(), Long.valueOf(getActiveTimeInMillis()), this.getStartTime(), this.getRequestUri(), Long.valueOf(interruptThreadThreshold), String.valueOf(this.getThread().getId())); Throwable th = new Throwable(); th.setStackTrace(this.getThread().getStackTrace()); log.warn(msg, th); } this.thread.interrupt(); } finally { this.interrupted = true; this.interruptionSemaphore.release(); } return true; }
public boolean interruptIfStuck(long interruptThreadThreshold) { if (!isMarkedAsStuck() || interruptionSemaphore == null || !this.interruptionSemaphore.tryAcquire()) { // if the semaphore is already acquired, it means that the // request thread got unstuck before we interrupted it return false; } try { if (log.isWarnEnabled()) { String msg = sm.getString( "stuckThreadDetectionValve.notifyStuckThreadInterrupted", this.getThread().getName(), Long.valueOf(getActiveTimeInMillis()), this.getStartTime(), this.getRequestUri(), Long.valueOf(interruptThreadThreshold), String.valueOf(this.getThread().getId())); Throwable th = new Throwable(); th.setStackTrace(this.getThread().getStackTrace()); log.warn(msg, th); } this.thread.interrupt(); } finally { this.interrupted = true; this.interruptionSemaphore.release(); } return true; }
completedStuckThreadsQueue.add( new CompletedStuckThread(monitoredThread.getThread().getName(), monitoredThread.getActiveTimeInMillis()));
monitoredThread.getActiveTimeInMillis()));
@Override public void backgroundProcess() { super.backgroundProcess(); long thresholdInMillis = threshold * 1000L; // Check monitored threads, being careful that the request might have // completed by the time we examine it for (MonitoredThread monitoredThread : activeThreads.values()) { long activeTime = monitoredThread.getActiveTimeInMillis(); if (activeTime >= thresholdInMillis && monitoredThread.markAsStuckIfStillRunning()) { int numStuckThreads = stuckCount.incrementAndGet(); notifyStuckThreadDetected(monitoredThread, activeTime, numStuckThreads); } if(interruptThreadThreshold > 0 && activeTime >= interruptThreadThreshold*1000L) { monitoredThread.interruptIfStuck(interruptThreadThreshold); } } // Check if any threads previously reported as stuck, have finished. for (CompletedStuckThread completedStuckThread = completedStuckThreadsQueue.poll(); completedStuckThread != null; completedStuckThread = completedStuckThreadsQueue.poll()) { int numStuckThreads = stuckCount.decrementAndGet(); notifyStuckThreadCompleted(completedStuckThread, numStuckThreads); } }
completedStuckThreadsQueue.add( new CompletedStuckThread(monitoredThread.getThread(), monitoredThread.getActiveTimeInMillis()));
@Override public void backgroundProcess() { super.backgroundProcess(); long thresholdInMillis = threshold * 1000; // Check monitored threads, being careful that the request might have // completed by the time we examine it for (MonitoredThread monitoredThread : activeThreads.values()) { long activeTime = monitoredThread.getActiveTimeInMillis(); if (activeTime >= thresholdInMillis && monitoredThread.markAsStuckIfStillRunning()) { int numStuckThreads = stuckCount.incrementAndGet(); notifyStuckThreadDetected(monitoredThread, activeTime, numStuckThreads); } } // Check if any threads previously reported as stuck, have finished. for (CompletedStuckThread completedStuckThread = completedStuckThreadsQueue.poll(); completedStuckThread != null; completedStuckThread = completedStuckThreadsQueue.poll()) { int numStuckThreads = stuckCount.decrementAndGet(); notifyStuckThreadCompleted(completedStuckThread.getName(), completedStuckThread.getTotalActiveTime(), numStuckThreads); } }
@Override public void backgroundProcess() { super.backgroundProcess(); long thresholdInMillis = threshold * 1000L; // Check monitored threads, being careful that the request might have // completed by the time we examine it for (MonitoredThread monitoredThread : activeThreads.values()) { long activeTime = monitoredThread.getActiveTimeInMillis(); if (activeTime >= thresholdInMillis && monitoredThread.markAsStuckIfStillRunning()) { int numStuckThreads = stuckCount.incrementAndGet(); notifyStuckThreadDetected(monitoredThread, activeTime, numStuckThreads); } if(interruptThreadThreshold > 0 && activeTime >= interruptThreadThreshold*1000L) { monitoredThread.interruptIfStuck(interruptThreadThreshold); } } // Check if any threads previously reported as stuck, have finished. for (CompletedStuckThread completedStuckThread = completedStuckThreadsQueue.poll(); completedStuckThread != null; completedStuckThread = completedStuckThreadsQueue.poll()) { int numStuckThreads = stuckCount.decrementAndGet(); notifyStuckThreadCompleted(completedStuckThread, numStuckThreads); } }