Author: markt Date: Tue Dec 1 19:33:44 2009 New Revision: 885889 URL: http://svn.apache.org/viewvc?rev=885889&view=rev Log: Move from a global system property to a per Context attribute for clearing static references. Change the default as this should no longer be an issue with modern JVMs and the other memory leak protection provided in Tomcat 7.
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java tomcat/trunk/webapps/docs/config/context.xml tomcat/trunk/webapps/docs/config/systemprops.xml Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=885889&r1=885888&r2=885889&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Tue Dec 1 19:33:44 2009 @@ -711,13 +711,13 @@ /** * 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 @@ */ 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 @@ } + /** + * 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 Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java?rev=885889&r1=885888&r2=885889&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Tue Dec 1 19:33:44 2009 @@ -119,9 +119,6 @@ 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 @@ 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 @@ 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 @@ // 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(); } Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java?rev=885889&r1=885888&r2=885889&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Tue Dec 1 19:33:44 2009 @@ -637,8 +637,13 @@ 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]); Modified: tomcat/trunk/webapps/docs/config/context.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/context.xml?rev=885889&r1=885888&r2=885889&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/config/context.xml (original) +++ tomcat/trunk/webapps/docs/config/context.xml Tue Dec 1 19:33:44 2009 @@ -328,6 +328,17 @@ 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 Modified: tomcat/trunk/webapps/docs/config/systemprops.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/systemprops.xml?rev=885889&r1=885888&r2=885889&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/config/systemprops.xml (original) +++ tomcat/trunk/webapps/docs/config/systemprops.xml Tue Dec 1 19:33:44 2009 @@ -403,20 +403,6 @@ 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> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org