From 1fb8df085056e232d7caccc08cafe9d96c9dc39d Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Sat, 21 Jul 2012 00:08:18 +0000 Subject: [PATCH] MATH-797 Performance: synchronization should ensure that the computation of each rule will be performed once, even if the factory is accessed from multiple threads. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1364024 13f79535-47bb-0310-9956-ffa450edef68 --- .../math3/analysis/integration/gauss/BaseRuleFactory.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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));