activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r520937 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/RedeliveryPolicy.java
Date Wed, 21 Mar 2007 16:19:27 GMT
Author: jstrachan
Date: Wed Mar 21 09:19:26 2007
New Revision: 520937

URL: http://svn.apache.org/viewvc?view=rev&rev=520937
Log:
avoided double check locking bugs

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

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/RedeliveryPolicy.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/RedeliveryPolicy.java?view=diff&rev=520937&r1=520936&r2=520937
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/RedeliveryPolicy.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/RedeliveryPolicy.java Wed
Mar 21 09:19:26 2007
@@ -97,15 +97,12 @@
         }
 
         if (useCollisionAvoidance) {
-            if (randomNumberGenerator == null) {
-                initRandomNumberGenerator();
-            }
-
-            /* 
+            /*
              * First random determines +/-, second random determines how far to
              * go in that direction. -cgs
              */
-            double variance = (randomNumberGenerator.nextBoolean() ? collisionAvoidanceFactor
: -collisionAvoidanceFactor) * randomNumberGenerator.nextDouble();
+            Random random = getRandomNumberGenerator();
+            double variance = (random.nextBoolean() ? collisionAvoidanceFactor : -collisionAvoidanceFactor)
* random.nextDouble();
             redeliveryDelay += redeliveryDelay * variance;
         }
 
@@ -128,10 +125,11 @@
         this.useExponentialBackOff = useExponentialBackOff;
     }
 
-    protected static synchronized void initRandomNumberGenerator() {
+    protected static synchronized Random getRandomNumberGenerator() {
         if (randomNumberGenerator == null) {
             randomNumberGenerator = new Random();
         }
+        return randomNumberGenerator;
     }
 
 }



Mime
View raw message