- Clients do not shutdown due to non-daemon threads hanging around.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@619004 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2008-02-06 14:48:42 +00:00
parent 149428b5bc
commit 527bd15a5a
1 changed files with 26 additions and 7 deletions

View File

@ -26,7 +26,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.activemq.command.KeepAliveInfo;
import org.apache.activemq.command.WireFormatInfo;
import org.apache.activemq.thread.Scheduler;
import org.apache.activemq.thread.SchedulerTimerTask;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -41,8 +40,11 @@ public class InactivityMonitor extends TransportFilter {
private static final Log LOG = LogFactory.getLog(InactivityMonitor.class);
private static final ThreadPoolExecutor ASYNC_TASKS;
private static final Timer READ_CHECK_TIMER = new Timer("InactivityMonitor ReadCheck");
private static final Timer WRITE_CHECK_TIMER = new Timer("InactivityMonitor WriteCheck");
private static int CHECKER_COUNTER;
private static Timer READ_CHECK_TIMER;
private static Timer WRITE_CHECK_TIMER;
private WireFormatInfo localWireFormatInfo;
private WireFormatInfo remoteWireFormatInfo;
private final AtomicBoolean monitorStarted = new AtomicBoolean(false);
@ -55,6 +57,7 @@ public class InactivityMonitor extends TransportFilter {
private SchedulerTimerTask writeCheckerTask;
private SchedulerTimerTask readCheckerTask;
private final Runnable readChecker = new Runnable() {
long lastRunTime;
public void run() {
@ -218,10 +221,17 @@ public class InactivityMonitor extends TransportFilter {
writeCheckerTask = new SchedulerTimerTask(writeChecker);
readCheckerTask = new SchedulerTimerTask(readChecker);
long writeCheckTime = checkTime/3;
synchronized( InactivityMonitor.class ) {
if( CHECKER_COUNTER == 0 ) {
READ_CHECK_TIMER = new Timer("InactivityMonitor ReadCheck");
WRITE_CHECK_TIMER = new Timer("InactivityMonitor WriteCheck");
}
CHECKER_COUNTER++;
WRITE_CHECK_TIMER.scheduleAtFixedRate(writeCheckerTask, writeCheckTime,writeCheckTime);
READ_CHECK_TIMER.scheduleAtFixedRate(readCheckerTask, checkTime,checkTime);
}
}
}
/**
*
@ -230,8 +240,17 @@ public class InactivityMonitor extends TransportFilter {
if (monitorStarted.compareAndSet(true, false)) {
readCheckerTask.cancel();
writeCheckerTask.cancel();
synchronized( InactivityMonitor.class ) {
WRITE_CHECK_TIMER.purge();
READ_CHECK_TIMER.purge();
CHECKER_COUNTER--;
if(CHECKER_COUNTER==0) {
WRITE_CHECK_TIMER.cancel();
READ_CHECK_TIMER.cancel();
WRITE_CHECK_TIMER = null;
READ_CHECK_TIMER = null;
}
}
}
}