You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2017/06/20 10:45:23 UTC

[4/6] struts git commit: WW-4805 Improves ProxyUtil performance via caching

WW-4805 Improves ProxyUtil performance via caching


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/64788152
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/64788152
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/64788152

Branch: refs/heads/master
Commit: 64788152910a84e7755a8302896a1fa2d5ecef7d
Parents: 7987c38
Author: Yasser Zamani <ya...@live.com>
Authored: Sun Jun 18 13:15:53 2017 +0430
Committer: Yasser Zamani <ya...@live.com>
Committed: Sun Jun 18 13:15:53 2017 +0430

----------------------------------------------------------------------
 .../com/opensymphony/xwork2/util/ProxyUtil.java | 28 ++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/64788152/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java b/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java
index 83e727c..b275bad 100644
--- a/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java
+++ b/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java
@@ -20,6 +20,8 @@ import org.apache.commons.lang3.reflect.FieldUtils;
 import org.apache.commons.lang3.reflect.MethodUtils;
 
 import java.lang.reflect.*;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * <code>ProxyUtil</code>
@@ -34,6 +36,11 @@ public class ProxyUtil {
     private static final String SPRING_SINGLETONTARGETSOURCE_CLASS_NAME = "org.springframework.aop.target.SingletonTargetSource";
     private static final String SPRING_TARGETCLASSAWARE_CLASS_NAME = "org.springframework.aop.TargetClassAware";
 
+    private static final Map<Class<?>, Boolean> isProxyCache =
+            new ConcurrentHashMap<>(256);
+    private static final Map<Member, Boolean> isProxyMemberCache =
+            new ConcurrentHashMap<>(256);
+
     /**
      * Determine the ultimate target class of the given instance, traversing
      * not only a top-level proxy but any number of nested proxies as well &mdash;
@@ -59,7 +66,16 @@ public class ProxyUtil {
      * @param object the object to check
      */
     public static boolean isProxy(Object object) {
-        return isSpringAopProxy(object);
+        Class<?> clazz = object.getClass();
+        Boolean flag = isProxyCache.get(clazz);
+        if (flag != null) {
+            return flag;
+        }
+
+        boolean isProxy = isSpringAopProxy(object);
+
+        isProxyCache.put(clazz, isProxy);
+        return isProxy;
     }
 
     /**
@@ -71,7 +87,15 @@ public class ProxyUtil {
         if (!isProxy(object))
             return false;
 
-        return isSpringProxyMember(member);
+        Boolean flag = isProxyMemberCache.get(member);
+        if (flag != null) {
+            return flag;
+        }
+
+        boolean isProxyMember = isSpringProxyMember(member);
+
+        isProxyMemberCache.put(member, isProxyMember);
+        return isProxyMember;
     }
 
     /**