Commits

Anonymous committed f52ffb6

Improving ognl compile performance XW-533

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

Comments (0)

Files changed (1)

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

 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) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.