[jboss-cvs] JBossAS SVN: r93092 - projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/lang.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 1 16:37:21 EDT 2009
Author: ALRubinger
Date: 2009-09-01 16:37:21 -0400 (Tue, 01 Sep 2009)
New Revision: 93092
Modified:
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/lang/SerializableMethod.java
Log:
[EJBTHREE-1909] Add a ClassLoader/Method cache to optimize toMethod calls
Modified: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/lang/SerializableMethod.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/lang/SerializableMethod.java 2009-09-01 20:27:02 UTC (rev 93091)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/lang/SerializableMethod.java 2009-09-01 20:37:21 UTC (rev 93092)
@@ -26,6 +26,8 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.jboss.ejb3.common.classloader.PrimitiveAwareClassLoader;
import org.jboss.logging.Logger;
@@ -80,6 +82,13 @@
*/
private String[] argumentTypes;
+ /**
+ * Cache of methods to a proposed ClassLoader. Used to
+ * limit the underlying ClassLoader calls in {@link SerializableMethod#toMethod(ClassLoader)}.
+ * Must be a Thread-safe impl
+ */
+ private transient Map<ClassLoader, Method> methodCache;
+
// ------------------------------------------------------------------------------||
// Constructors -----------------------------------------------------------------||
// ------------------------------------------------------------------------------||
@@ -229,6 +238,23 @@
*/
public Method toMethod(ClassLoader cl)
{
+ // Get Cache
+ Map<ClassLoader, Method> cache = this.getMethodCache();
+ if (cache == null)
+ {
+ this.setMethodCache(new ConcurrentHashMap<ClassLoader, Method>());
+ cache = this.getMethodCache();
+ }
+
+ // Obtain from cache
+ final Method method = cache.get(cl);
+
+ // If found, return it
+ if (method != null)
+ {
+ return method;
+ }
+
// Load the Class described by the Method
Class<?> invokingClass = this.getClassType(cl);
@@ -254,6 +280,9 @@
throw new RuntimeException("Method " + this + " does not exist in " + invokingClass.getName(), nsme);
}
+ // Add method to the cache
+ cache.put(cl, invokedMethod);
+
// Return
return invokedMethod;
}
@@ -296,7 +325,6 @@
{
// Perform assertions
assert cl != null : ClassLoader.class.getSimpleName() + " must be defined.";
-
// Load the Class described by the Method
Class<?> clazz = null;
@@ -379,4 +407,20 @@
this.actualClassName = actualClassName;
}
+ /**
+ * @return the methodCache
+ */
+ private Map<ClassLoader, Method> getMethodCache()
+ {
+ return methodCache;
+ }
+
+ /**
+ * @param methodCache the methodCache to set
+ */
+ private void setMethodCache(Map<ClassLoader, Method> methodCache)
+ {
+ this.methodCache = methodCache;
+ }
+
}
More information about the jboss-cvs-commits
mailing list