Enhance fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=50078
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 14 Oct 2010 17:37:20 +0000 (17:37 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 14 Oct 2010 17:37:20 +0000 (17:37 +0000)
Make cache sizes configurable

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1022623 13f79535-47bb-0310-9956-ffa450edef68

java/javax/el/BeanELResolver.java
java/org/apache/el/lang/ExpressionBuilder.java
webapps/docs/config/systemprops.xml

index f93f4a6..3476dc1 100644 (file)
@@ -26,6 +26,8 @@ import java.lang.reflect.Array;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -35,10 +37,31 @@ import java.util.concurrent.ConcurrentHashMap;
 
 public class BeanELResolver extends ELResolver {
 
+    private static final int CACHE_SIZE;
+    private static final String CACHE_SIZE_PROP =
+        "org.apache.el.BeanELResolver.CACHE_SIZE";
+
+    static {
+        if (System.getSecurityManager() == null) {
+            CACHE_SIZE = Integer.parseInt(
+                    System.getProperty(CACHE_SIZE_PROP, "1000"));
+        } else {
+            CACHE_SIZE = AccessController.doPrivileged(
+                    new PrivilegedAction<Integer>() {
+
+                    @Override
+                    public Integer run() {
+                        return Integer.valueOf(
+                                System.getProperty(CACHE_SIZE_PROP, "1000"));
+                    }
+                }).intValue();
+        }
+    }
+
     private final boolean readOnly;
 
     private final ConcurrentCache<String, BeanProperties> cache =
-        new ConcurrentCache<String, BeanProperties>(1000);
+        new ConcurrentCache<String, BeanProperties>(CACHE_SIZE);
 
     public BeanELResolver() {
         this.readOnly = false;
index 079c733..1c0c3e5 100644 (file)
@@ -19,6 +19,8 @@ package org.apache.el.lang;
 
 import java.io.StringReader;
 import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 import javax.el.ELContext;
 import javax.el.ELException;
@@ -49,8 +51,29 @@ import org.apache.el.util.MessageFactory;
  */
 public final class ExpressionBuilder implements NodeVisitor {
 
+    private static final int CACHE_SIZE;
+    private static final String CACHE_SIZE_PROP =
+        "org.apache.el.ExpressionBuilder.CACHE_SIZE";
+
+    static {
+        if (System.getSecurityManager() == null) {
+            CACHE_SIZE = Integer.parseInt(
+                    System.getProperty(CACHE_SIZE_PROP, "5000"));
+        } else {
+            CACHE_SIZE = AccessController.doPrivileged(
+                    new PrivilegedAction<Integer>() {
+
+                    @Override
+                    public Integer run() {
+                        return Integer.valueOf(
+                                System.getProperty(CACHE_SIZE_PROP, "5000"));
+                    }
+                }).intValue();
+        }
+    }
+
     private static final ConcurrentCache<String, Node> cache =
-        new ConcurrentCache<String, Node>(5000);
+        new ConcurrentCache<String, Node>(CACHE_SIZE);
 
     private FunctionMapper fnMapper;
 
index 591bc7c..5ce3c7a 100644 (file)
       <code>false</code> will be used.</p>
     </property>
 
+    <property name="org.apache.el.BeanELResolver.CACHE_SIZE">
+      <p>The number of javax.el.BeanELResolver.BeanProperties objects that will
+      be cached by the EL Parser. If not specified, the default of
+      <code>1000</code> will be used.</p>
+    </property>
+
+    <property name="org.apache.el.ExpressionBuilder.CACHE_SIZE">
+      <p>The number of parsed EL expressions that will be cached by the EL
+      Parser. If not specified, the default of <code>5000</code> will be used.
+      </p>
+    </property>
+
   </properties>
 </section>