You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2010/04/04 21:08:34 UTC

svn commit: r930735 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java

Author: doogie
Date: Sun Apr  4 19:08:34 2010
New Revision: 930735

URL: http://svn.apache.org/viewvc?rev=930735&view=rev
Log:
Remove synchronized here too; again, since we are adding/removing from a
cache, if 2 threads happen to not find anything, then it will just cause
a little bit of duplicated work.  It's better to that, then have a block
occur.  Class loading causes static constructors to run, which might end
up calling into the thread context class loader, which then might end up
starting other threads, which then could end up calling back into this
code path; instant dead-lock.  So, removing a lock stops the dead-lock
possibility.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java?rev=930735&r1=930734&r2=930735&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java Sun Apr  4 19:08:34 2010
@@ -46,7 +46,7 @@ public class ObjectType {
 
     public static final Object NULL = new NullObject();
 
-    protected static Map<String, Class<?>> classCache = FastMap.newInstance();
+    protected static FastMap<String, Class<?>> classCache = FastMap.newInstance();
 
     public static final String LANG_PACKAGE = "java.lang."; // We will test both the raw value and this + raw value
     public static final String SQL_PACKAGE = "java.sql.";   // We will test both the raw value and this + raw value
@@ -109,14 +109,10 @@ public class ObjectType {
         } catch (Exception e) {
             theClass = classCache.get(className);
             if (theClass == null) {
-                synchronized (ObjectType.class) {
-                    theClass = classCache.get(className);
-                    if (theClass == null) {
-                        theClass = Class.forName(className);
-                        if (theClass != null) {
-                            if (Debug.verboseOn()) Debug.logVerbose("Loaded Class: " + theClass.getName(), module);
-                            classCache.put(className, theClass);
-                        }
+                theClass = Class.forName(className);
+                if (theClass != null) {
+                    if (classCache.putIfAbsent(className, theClass) == null) {
+                        if (Debug.verboseOn()) Debug.logVerbose("Loaded Class: " + theClass.getName(), module);
                     }
                 }
             }