[jboss-cvs] JBossAS SVN: r107385 - branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 4 10:48:32 EDT 2010


Author: jaikiran
Date: 2010-08-04 10:48:32 -0400 (Wed, 04 Aug 2010)
New Revision: 107385

Modified:
   branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/TimerImpl.java
Log:
JBPAPP-4681 Get rid of the loop used for computing next timeout

Modified: branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/TimerImpl.java
===================================================================
--- branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/TimerImpl.java	2010-08-04 13:04:51 UTC (rev 107384)
+++ branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/TimerImpl.java	2010-08-04 14:48:32 UTC (rev 107385)
@@ -151,15 +151,16 @@
       // for the *missed* timeout atleast once. Here we create a single action
       // timeout which will fire immediately. At the same time we also (re)compute the 
       // actual next timeout *from now* and create a periodic timer task for the same
-      if (nextTimeout.before(now))
+      if (nextTimeout.before(now) && periode > 0)
       {
-         long next = nextTimeout.getTime();
+         long timeInThePast = nextTimeout.getTime();
          long current = now.getTime(); 
+         
          // recompute the next timeout based on the current time
-         while (next < current)
-         {
-            next += periode;
-         }
+         long timeElapsedSinceLastExpectedTimeout = (current - timeInThePast) % periode;
+         long timeRemainingUntilNextTimeout = timeElapsedSinceLastExpectedTimeout == 0 ? 0 : periode - timeElapsedSinceLastExpectedTimeout;
+         long next = current + timeRemainingUntilNextTimeout;
+         
          this.nextExpire = next;
          // persist the recomputed next timeout
          this.persistNextTimeout();



More information about the jboss-cvs-commits mailing list