diff --git a/src/main/java/org/apache/commons/math3/analysis/integration/gauss/BaseRuleFactory.java b/src/main/java/org/apache/commons/math3/analysis/integration/gauss/BaseRuleFactory.java index e8d0b68e7..b4795ee1e 100644 --- a/src/main/java/org/apache/commons/math3/analysis/integration/gauss/BaseRuleFactory.java +++ b/src/main/java/org/apache/commons/math3/analysis/integration/gauss/BaseRuleFactory.java @@ -68,13 +68,14 @@ public abstract class BaseRuleFactory { /** * Gets a rule. - * Rules are computed once, and cached. + * Synchronization ensures that rules will be computed and added to the + * cache at most once. * The returned rule is a reference into the cache. * * @param numberOfPoints Order of the rule to be retrieved. * @return the points and weights corresponding to the given order. */ - protected Pair getRuleInternal(int numberOfPoints) { + protected synchronized Pair getRuleInternal(int numberOfPoints) { final Pair rule = pointsAndWeights.get(numberOfPoints); if (rule == null) { addRule(computeRule(numberOfPoints));