commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r885485 - /commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/util/Introspector.java
Date Mon, 30 Nov 2009 16:39:19 GMT
Author: sebb
Date: Mon Nov 30 16:39:19 2009
New Revision: 885485

URL: http://svn.apache.org/viewvc?rev=885485&view=rev
Log:
Use IODH idiom instead of volatile and double-checked locking

Modified:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/util/Introspector.java

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/util/Introspector.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/util/Introspector.java?rev=885485&r1=885484&r2=885485&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/util/Introspector.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/util/Introspector.java
Mon Nov 30 16:39:19 2009
@@ -33,8 +33,12 @@
  * @since 1.0
  */
 public class Introspector {
-    /** The default uberspector that handles all introspection patterns. */
-    private static volatile Uberspect uberSpect;
+    
+    private static class UberspectHolder{// Implements init on demand holder idiom
+        /** The default uberspector that handles all introspection patterns. */
+        private static final Uberspect UBERSPECT = new UberspectImpl(LogFactory.getLog(Introspector.class));
+    }
+
     /** The logger to use for all warnings & errors. */
     protected final Log rlog;
     /** The (low level) introspector to use for introspection services. */
@@ -105,20 +109,9 @@
      * instead of the default one.</p>
      *  @return Uberspect the default uberspector instance.
      */
-    // CSOFF: DoubleCheckedLocking
     public static Uberspect getUberspect() {
-        // uses a double-locking pattern
-        if (uberSpect == null) {
-            synchronized (Uberspect.class) {
-                if (uberSpect == null) {
-                    Log logger = LogFactory.getLog(Introspector.class);
-                    uberSpect = new UberspectImpl(logger);
-                }
-            }
-        }
-        return uberSpect;
+        return UberspectHolder.UBERSPECT;
     }
-    // CSON: DoubleCheckedLocking
 
     /**
      * Creates a new instance of Uberspect.



Mime
View raw message