commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r762102 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java site/xdoc/changes.xml
Date Sun, 05 Apr 2009 15:16:05 GMT
Author: luc
Date: Sun Apr  5 15:16:03 2009
New Revision: 762102

URL: http://svn.apache.org/viewvc?rev=762102&view=rev
Log:
Fixed threading issues with UnivariateRealSolverUtils factory
Jira: MATH-254

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java?rev=762102&r1=762101&r2=762102&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
Sun Apr  5 15:16:03 2009
@@ -33,9 +33,6 @@
         super();
     }
     
-    /** Cached solver factory */
-    private static UnivariateRealSolverFactory factory = null;
-
     /**
      * Convenience method to find a zero of a univariate real function.  A default
      * solver is used. 
@@ -53,7 +50,7 @@
     public static double solve(UnivariateRealFunction f, double x0, double x1)
     throws ConvergenceException, FunctionEvaluationException {
         setup(f);
-        return factory.newDefaultSolver().solve(f, x0, x1);
+        return LazyHolder.FACTORY.newDefaultSolver().solve(f, x0, x1);
     }
 
     /**
@@ -77,7 +74,7 @@
             FunctionEvaluationException {    
        
         setup(f);
-        UnivariateRealSolver solver = factory.newDefaultSolver();
+        UnivariateRealSolver solver = LazyHolder.FACTORY.newDefaultSolver();
         solver.setAbsoluteAccuracy(absoluteAccuracy);
         return solver.solve(f, x0, x1);
     }
@@ -219,19 +216,22 @@
     
     /**
      * Checks to see if f is null, throwing IllegalArgumentException if so.
-     * Also initializes factory if factory is null.
-     * 
      * @param f  input function
      * @throws IllegalArgumentException if f is null
      */
     private static void setup(UnivariateRealFunction f) {
-       
         if (f == null) {
             throw new IllegalArgumentException("function can not be null.");    
         }
-        
-        if (factory == null) {
-            factory = UnivariateRealSolverFactory.newInstance();
-        }       
     }
+
+    /** Holder for the factory.
+     * <p>We use here the Initialization On Demand Holder Idiom.</p>
+     */
+    private static class LazyHolder {
+        /** Cached solver factory */
+        private static final UnivariateRealSolverFactory FACTORY =
+            UnivariateRealSolverFactory.newInstance();
+    }
+
 }

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=762102&r1=762101&r2=762102&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sun Apr  5 15:16:03 2009
@@ -39,7 +39,10 @@
   </properties>
   <body>
     <release version="2.0" date="TBD" description="TBD">
-      <action dev="luc" type="add" issue="MATH-255" due-to="Sebb">
+      <action dev="luc" type="fix" issue="MATH-254" due-to="Sebb">
+        Fixed threading issues with UnivariateRealSolverUtils factory
+      </action>
+      <action dev="luc" type="fix" issue="MATH-255" due-to="Sebb">
         Reduced visibility of MessagesResources_fr.contents field to private
       </action>
       <action dev="luc" type="add" issue="MATH-256" >



Mime
View raw message