mirror of
https://github.com/apache/activemq.git
synced 2025-02-28 13:19:07 +00:00
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:
parent
a2aed3d732
commit
2a3f9e38ea
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user