From 55db7ee17fd7e0df0fadbcaf7d3434a7406aa264 Mon Sep 17 00:00:00 2001 From: markt Date: Tue, 1 Dec 2009 19:33:44 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@885889 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/core/StandardContext.java | 43 ++++++++++++++++++++-- .../apache/catalina/loader/WebappClassLoader.java | 35 ++++++++++++++++-- java/org/apache/catalina/loader/WebappLoader.java | 9 ++++- webapps/docs/config/context.xml | 11 ++++++ webapps/docs/config/systemprops.xml | 14 ------- 5 files changed, 88 insertions(+), 24 deletions(-) diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index ef6d31e57..9b77f7d93 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -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 false. If not specified, the default value of + * false 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 diff --git a/java/org/apache/catalina/loader/WebappClassLoader.java b/java/org/apache/catalina/loader/WebappClassLoader.java index ef891427d..2b0f546ef 100644 --- a/java/org/apache/catalina/loader/WebappClassLoader.java +++ b/java/org/apache/catalina/loader/WebappClassLoader.java @@ -119,9 +119,6 @@ public class WebappClassLoader private static final List JVM_THREAD_GROUP_NAMES = new ArrayList(); - 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 false. If not specified, the default value of + * false 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(); } diff --git a/java/org/apache/catalina/loader/WebappLoader.java b/java/org/apache/catalina/loader/WebappLoader.java index 6d1d59544..58367e90a 100644 --- a/java/org/apache/catalina/loader/WebappLoader.java +++ b/java/org/apache/catalina/loader/WebappLoader.java @@ -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]); diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml index 96239e70f..e79d8ad97 100644 --- a/webapps/docs/config/context.xml +++ b/webapps/docs/config/context.xml @@ -328,6 +328,17 @@ of the flag is true.

+ +

If true, 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 true. Applications without memory leaks using recent + JVMs should operate correctly with this attribute set to + false. If not specified, the default value of + false will be used.

+
+

Whether the context should process TLDs on startup. The default is true. The false setting is intended for special cases diff --git a/webapps/docs/config/systemprops.xml b/webapps/docs/config/systemprops.xml index 06f05637c..7a43ba025 100644 --- a/webapps/docs/config/systemprops.xml +++ b/webapps/docs/config/systemprops.xml @@ -403,20 +403,6 @@ configured on the Engine element.

- -

If true, 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 option is - true.

-

Applications without memory leaks using recent JVMs should operate - correctly with this option set to false.

-

If not specified, the default value of true will be used. -

-
-

The URL for the catalina.properties configuration file.

-- 2.11.0