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
This commit is contained in:
parent
6f92d77bb1
commit
1fb8df0850
|
@ -68,13 +68,14 @@ public abstract class BaseRuleFactory<T extends Number> {
|
|||
|
||||
/**
|
||||
* 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<T[], T[]> getRuleInternal(int numberOfPoints) {
|
||||
protected synchronized Pair<T[], T[]> getRuleInternal(int numberOfPoints) {
|
||||
final Pair<T[], T[]> rule = pointsAndWeights.get(numberOfPoints);
|
||||
if (rule == null) {
|
||||
addRule(computeRule(numberOfPoints));
|
||||
|
|
Loading…
Reference in New Issue