1. opensymphony
  2. xwork

Commits

mrdon  committed f52ffb6

Improving ognl compile performance XW-533

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1626e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 222e699
  • Branches master

Comments (0)

Files changed (1)

File src/java/com/opensymphony/xwork2/ognl/OgnlUtil.java

View file
  • Ignore whitespace
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 
 /**
 public class OgnlUtil {
 
     private static final Log log = LogFactory.getLog(OgnlUtil.class);
-    private HashMap expressions = new HashMap();
-    private HashMap beanInfoCache = new HashMap();
+    private ConcurrentHashMap<String,Object> expressions = new ConcurrentHashMap<String,Object>();
+    private ConcurrentHashMap<Class,BeanInfo> beanInfoCache = new ConcurrentHashMap<Class,BeanInfo>();
     
     private TypeConverter defaultConverter;
     
 
 
     public Object compile(String expression) throws OgnlException {
-        synchronized (expressions) {
-            Object o = expressions.get(expression);
-
-            if (o == null) {
-                o = Ognl.parseExpression(expression);
-                expressions.put(expression, o);
-            }
-
-            return o;
+        Object o = expressions.get(expression);
+        if (o == null) {
+            o = Ognl.parseExpression(expression);
+            expressions.put(expression, o);
         }
+        return o;
     }
 
     /**
      * @throws IntrospectionException is thrown if an exception occurs during introspection.
      */
     public BeanInfo getBeanInfo(Object from) throws IntrospectionException {
-        synchronized (beanInfoCache) {
-            BeanInfo beanInfo;
-            beanInfo = (BeanInfo) beanInfoCache.get(from.getClass());
-            if (beanInfo == null) {
-                beanInfo = Introspector.getBeanInfo(from.getClass(), Object.class);
-                beanInfoCache.put(from.getClass(), beanInfo);
-            }
-            return beanInfo;
+        BeanInfo beanInfo;
+        beanInfo = (BeanInfo) beanInfoCache.get(from.getClass());
+        if (beanInfo == null) {
+            beanInfo = Introspector.getBeanInfo(from.getClass(), Object.class);
+            beanInfoCache.putIfAbsent(from.getClass(), beanInfo);
         }
+        return beanInfo;
     }
 
     void internalSetProperty(String name, Object value, Object o, Map context, boolean throwPropertyExceptions) {