Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47987
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 21 Oct 2009 20:57:14 +0000 (20:57 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 21 Oct 2009 20:57:14 +0000 (20:57 +0000)
Limit size of not found resources cache

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

java/org/apache/catalina/loader/WebappClassLoader.java

index 442eb0b..10a00f3 100644 (file)
@@ -41,6 +41,8 @@ import java.util.Collection;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
 import java.util.Vector;
 import java.util.jar.Attributes;
 import java.util.jar.JarEntry;
@@ -238,7 +240,14 @@ public class WebappClassLoader
      * The cache of ResourceEntry for classes and resources we have loaded,
      * keyed by resource name.
      */
-    protected HashMap<String, ResourceEntry> resourceEntries = new HashMap<String, ResourceEntry>();
+    protected HashMap<String, ResourceEntry> resourceEntries =
+            new LinkedHashMap<String, ResourceEntry>() {
+        private static final long serialVersionUID = 1L;
+        protected boolean removeEldestEntry(
+                Map.Entry<String, ResourceEntry> eldest) {
+            return size() > 1000;
+        }
+    };
 
 
     /**