activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r629859 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java
Date Thu, 21 Feb 2008 16:39:16 GMT
Author: chirino
Date: Thu Feb 21 08:39:16 2008
New Revision: 629859

URL: http://svn.apache.org/viewvc?rev=629859&view=rev
Log:
Gaurd against too many read checks happening back to back.

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=629859&r1=629858&r2=629859&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
Thu Feb 21 08:39:16 2008
@@ -57,16 +57,30 @@
     private SchedulerTimerTask writeCheckerTask;
     private SchedulerTimerTask readCheckerTask;
 
+    private long readCheckTime;
+    private long writeCheckTime;
     
     private final Runnable readChecker = new Runnable() {
         long lastRunTime;
         public void run() {
             long now = System.currentTimeMillis();
+            long elapsed = (now-lastRunTime);
+
             if( lastRunTime != 0 && LOG.isDebugEnabled() ) {
-                LOG.debug(""+(now-lastRunTime)+" ms elapsed since last read check.");
-              
+                LOG.debug(""+elapsed+" ms elapsed since last read check.");
             }
-            lastRunTime = now; 
+            
+            // Perhaps the timer executed a read check late.. and then executes
+            // the next read check on time which causes the time elapsed between
+            // read checks to be small..
+            
+            // If less than 90% of the read check Time elapsed then abort this readcheck.

+            if( elapsed < (readCheckTime * 9 / 10) ) {
+                LOG.debug("Aborting read check.. Not enough time elapsed since last read
check.");
+                return;
+            }
+            
+            lastRunTime = now;
             readCheck();
         }
     };
@@ -215,12 +229,12 @@
             return;
         }
 
-        long checkTime = Math.min(localWireFormatInfo.getMaxInactivityDuration(), remoteWireFormatInfo.getMaxInactivityDuration());
-        if (checkTime > 0) {
+        readCheckTime = Math.min(localWireFormatInfo.getMaxInactivityDuration(), remoteWireFormatInfo.getMaxInactivityDuration());
+        if (readCheckTime > 0) {
             monitorStarted.set(true);
             writeCheckerTask = new SchedulerTimerTask(writeChecker);
             readCheckerTask = new  SchedulerTimerTask(readChecker);
-            long writeCheckTime = checkTime/3;
+            writeCheckTime = readCheckTime/3;
             synchronized( InactivityMonitor.class ) {
             	if( CHECKER_COUNTER == 0 ) {
             	    READ_CHECK_TIMER = new Timer("InactivityMonitor ReadCheck");
@@ -228,7 +242,7 @@
             	}
             	CHECKER_COUNTER++;
                 WRITE_CHECK_TIMER.scheduleAtFixedRate(writeCheckerTask, writeCheckTime,writeCheckTime);
-                READ_CHECK_TIMER.scheduleAtFixedRate(readCheckerTask, checkTime,checkTime);
+                READ_CHECK_TIMER.scheduleAtFixedRate(readCheckerTask, readCheckTime,readCheckTime);
             }
         }
     }



Mime
View raw message