Move from a global system property to a per Context attribute for clearing static...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 1 Dec 2009 19:33:44 +0000 (19:33 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 1 Dec 2009 19:33:44 +0000 (19:33 +0000)
Change the default as this should no longer be an issue with modern JVMs and the other memory leak protection provided in Tomcat 7.

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

java/org/apache/catalina/core/StandardContext.java
java/org/apache/catalina/loader/WebappClassLoader.java
java/org/apache/catalina/loader/WebappLoader.java
webapps/docs/config/context.xml
webapps/docs/config/systemprops.xml

index ef6d31e..9b77f7d 100644 (file)
@@ -711,13 +711,13 @@ public class StandardContext
     /**
      * Attribute value used to turn on/off XML validation
      */
-     private boolean tldValidation = false;
+    private boolean tldValidation = false;
 
 
     /**
      * Attribute value used to turn on/off TLD XML namespace validation
      */
-     private boolean tldNamespaceAware = false;
+    private boolean tldNamespaceAware = false;
 
 
     /**
@@ -736,8 +736,17 @@ public class StandardContext
      */
     private JarScanner jarScanner = null;
 
-
-
+    /**
+     * Should Tomcat attempt to null out any static or final fields from loaded
+     * classes when a web application is stopped as a work around for apparent
+     * garbage collection bugs and application coding errors. There have been
+     * some issues reported with log4j when this option is true. Applications
+     * without memory leaks using recent JVMs should operate correctly with this
+     * option set to <code>false</code>. If not specified, the default value of
+     * <code>false</code> will be used. 
+     */
+    private boolean clearReferencesStatic = false;
+    
     // ----------------------------------------------------- Context Properties
 
 
@@ -2069,6 +2078,32 @@ public class StandardContext
     }
 
 
+    /**
+     * Return the clearReferencesStatic flag for this Context.
+     */
+    public boolean getClearReferencesStatic() {
+
+        return (this.clearReferencesStatic);
+
+    }
+
+
+    /**
+     * Set the clearReferencesStatic feature for this Context.
+     *
+     * @param clearReferencesStatic The new flag value
+     */
+    public void setClearReferencesStatic(boolean clearReferencesStatic) {
+
+        boolean oldClearReferencesStatic = this.clearReferencesStatic;
+        this.clearReferencesStatic = clearReferencesStatic;
+        support.firePropertyChange("clearReferencesStatic",
+                                   oldClearReferencesStatic,
+                                   this.clearReferencesStatic);
+
+    }
+
+
     // -------------------------------------------------------- Context Methods
 
 
index ef89142..2b0f546 100644 (file)
@@ -119,9 +119,6 @@ public class WebappClassLoader
     private static final List<String> JVM_THREAD_GROUP_NAMES =
         new ArrayList<String>();
 
-    public static final boolean ENABLE_CLEAR_REFERENCES = 
-        Boolean.valueOf(System.getProperty("org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES", "true")).booleanValue();
-    
     static {
         JVM_THREAD_GROUP_NAMES.add("system");
         JVM_THREAD_GROUP_NAMES.add("RMI Runtime");
@@ -411,6 +408,17 @@ public class WebappClassLoader
     protected Permission allPermission = new java.security.AllPermission();
 
 
+    /**
+     * Should Tomcat attempt to null out any static or final fields from loaded
+     * classes when a web application is stopped as a work around for apparent
+     * garbage collection bugs and application coding errors. There have been
+     * some issues reported with log4j when this option is true. Applications
+     * without memory leaks using recent JVMs should operate correctly with this
+     * option set to <code>false</code>. If not specified, the default value of
+     * <code>false</code> will be used. 
+     */
+    private boolean clearReferencesStatic = false;
+
     // ------------------------------------------------------------- Properties
 
 
@@ -564,6 +572,25 @@ public class WebappClassLoader
          parent = pcl;
      }
 
+     /**
+      * Return the clearReferencesStatic flag for this Context.
+      */
+     public boolean getClearReferencesStatic() {
+         return (this.clearReferencesStatic);
+     }
+
+
+     /**
+      * Set the clearReferencesStatic feature for this Context.
+      *
+      * @param clearReferencesStatic The new flag value
+      */
+     public void setClearReferencesStatic(boolean clearReferencesStatic) {
+         this.clearReferencesStatic = clearReferencesStatic;
+     }
+
+
+
     // ------------------------------------------------------- Reloader Methods
 
 
@@ -1653,7 +1680,7 @@ public class WebappClassLoader
         
         // Null out any static or final fields from loaded classes,
         // as a workaround for apparent garbage collection bugs
-        if (ENABLE_CLEAR_REFERENCES) {
+        if (clearReferencesStatic) {
             clearReferencesStaticFinal();
         }
         
index 6d1d595..58367e9 100644 (file)
@@ -637,8 +637,13 @@ public class WebappLoader
             classLoader = createClassLoader();
             classLoader.setResources(container.getResources());
             classLoader.setDelegate(this.delegate);
-            if (container instanceof StandardContext)
-                classLoader.setAntiJARLocking(((StandardContext) container).getAntiJARLocking());
+            if (container instanceof StandardContext) {
+                classLoader.setAntiJARLocking(
+                        ((StandardContext) container).getAntiJARLocking());
+                classLoader.setClearReferencesStatic(
+                        ((StandardContext) container).getClearReferencesStatic());
+                
+            }
 
             for (int i = 0; i < repositories.length; i++) {
                 classLoader.addRepository(repositories[i]);
index 96239e7..e79d8ad 100644 (file)
         of the flag is <code>true</code>.</p>
       </attribute>
 
+      <attribute name="clearReferencesStatic" required = "false">
+        <p>If <code>true</code>, Tomcat attempts to null out any static or final
+        fields from loaded classes when a web application is stopped as a work
+        around for apparent garbage collection bugs and application coding
+        errors. There have been some issues reported with log4j when this
+        is <code>true</code>. Applications without memory leaks using recent
+        JVMs should operate correctly with this attribute set to
+        <code>false</code>. If not specified, the default value of
+        <code>false</code> will be used.</p>
+      </attribute>
+
       <attribute name="processTlds" required="false">
         <p>Whether the context should process TLDs on startup.  The default
         is true.  The false setting is intended for special cases
index 06f0563..7a43ba0 100644 (file)
       configured on the <a href="engine.html">Engine</a> element.</p>
     </property>
 
-    <property
-    name="org.apache.catalina.loader. WebappClassLoader.ENABLE_CLEAR_REFERENCES">
-      <p>If <code>true</code>, Tomcat attempts to null out any static or final
-      fields from loaded classes when a web application is stopped as a work
-      around for apparent garbage collection bugs and application coding errors.
-      </p>
-      <p>There have been some issues reported with log4j when this option is
-      <code>true</code>.</p>
-      <p>Applications without memory leaks using recent JVMs should operate
-      correctly with this option set to <code>false</code>.</p>
-      <p>If not specified, the default value of <code>true</code> will be used.
-      </p>
-    </property>
-
     <property name="catalina.config">
       <p>The URL for the catalina.properties configuration file.</p>
     </property>