activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r619004 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java
Date Wed, 06 Feb 2008 14:48:44 GMT
Author: chirino
Date: Wed Feb  6 06:48:42 2008
New Revision: 619004

URL: http://svn.apache.org/viewvc?rev=619004&view=rev
Log:
 - Clients do not shutdown due to non-daemon threads hanging around.


Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java?rev=619004&r1=619003&r2=619004&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java
Wed Feb  6 06:48:42 2008
@@ -26,7 +26,6 @@
 
 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 @@
 
     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 @@
     private SchedulerTimerTask writeCheckerTask;
     private SchedulerTimerTask readCheckerTask;
 
+    
     private final Runnable readChecker = new Runnable() {
         long lastRunTime;
         public void run() {
@@ -218,8 +221,15 @@
             writeCheckerTask = new SchedulerTimerTask(writeChecker);
             readCheckerTask = new  SchedulerTimerTask(readChecker);
             long writeCheckTime = checkTime/3;
-            WRITE_CHECK_TIMER.scheduleAtFixedRate(writeCheckerTask, writeCheckTime,writeCheckTime);
-            READ_CHECK_TIMER.scheduleAtFixedRate(readCheckerTask, checkTime,checkTime);
+            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 @@
         if (monitorStarted.compareAndSet(true, false)) {
             readCheckerTask.cancel();
             writeCheckerTask.cancel();
-            WRITE_CHECK_TIMER.purge();
-            READ_CHECK_TIMER.purge();
+            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;
+	            }
+            }
         }
     }
     



Mime
View raw message