avoided double check locking bugs

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@520937 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2007-03-21 16:19:26 +00:00
parent a2aed3d732
commit 2a3f9e38ea

View File

@ -97,15 +97,12 @@ public class RedeliveryPolicy implements Cloneable, Serializable {
}
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 @@ public class RedeliveryPolicy implements Cloneable, Serializable {
this.useExponentialBackOff = useExponentialBackOff;
}
protected static synchronized void initRandomNumberGenerator() {
protected static synchronized Random getRandomNumberGenerator() {
if (randomNumberGenerator == null) {
randomNumberGenerator = new Random();
}
return randomNumberGenerator;
}
}