* <code>false</code> will be used.
*/
private boolean clearReferencesStopThreads = false;
-
+
+ /**
+ * Should Tomcat attempt to clear any ThreadLocal objects that are instances
+ * of classes loaded by this class loader. Failure to remove any such
+ * objects will result in a memory leak on web application stop, undeploy or
+ * reload. It is disabled by default since the clearing of the ThreadLocal
+ * objects is not performed in a thread-safe manner.
+ */
+ private boolean clearReferencesThreadLocals = false;
+
/**
* Should the effective web.xml be logged when the context starts?
*/
/**
+ * Return the clearReferencesThreadLocals flag for this Context.
+ */
+ public boolean getClearReferencesThreadLocals() {
+
+ return (this.clearReferencesThreadLocals);
+
+ }
+
+
+ /**
+ * Set the clearReferencesStopThreads feature for this Context.
+ *
+ * @param clearReferencesStopThreads The new flag value
+ */
+ public void setClearReferencesThreadLocals(
+ boolean clearReferencesThreadLocals) {
+
+ boolean oldClearReferencesThreadLocals =
+ this.clearReferencesThreadLocals;
+ this.clearReferencesThreadLocals = clearReferencesThreadLocals;
+ support.firePropertyChange("clearReferencesStopThreads",
+ oldClearReferencesThreadLocals,
+ this.clearReferencesThreadLocals);
+
+ }
+
+
+ /**
* Has this context been initialized?
*/
public boolean isInitialized() {
webappClassLoader.clearReferencesResourceBundlesFail=Failed to clear ResourceBundle references for web application [{0}]
webappClassLoader.clearRmiInfo=Failed to find class sun.rmi.transport.Target to clear context class loader for web application [{0}]. This is expected on non-Sun JVMs.
webappClassLoader.clearRmiFail=Failed to clear context class loader referenced from sun.rmi.transport.Target for web application [{0}]
-webappClassLoader.clearThreadLocalDebug=The web application [{0}] created a ThreadLocal with key of type [{1}] (value [{2}]). The ThreadLocal has been correctly set to null and the key will be removed by GC. However, to simplify the process of tracing memory leaks, the key has been forcibly removed.
-webappClassLoader.clearThreadLocal=The web application [{0}] created a ThreadLocal with key of type [{1}] (value [{2}]) and a value of type [{3}] (value [{4}]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
+webappClassLoader.clearThreadLocalDebug=The web application [{0}] created a ThreadLocal with key of type [{1}] (value [{2}]). The ThreadLocal has been correctly set to null and the key will be removed by GC.
+webappClassLoader.clearThreadLocal=The web application [{0}] created a ThreadLocal with key of type [{1}] (value [{2}]) and a value of type [{3}] (value [{4}]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
+webappClassLoader.clearThreadLocalDebugClear=To simplify the process of tracing memory leaks, the key has been forcibly removed.
+webappClassLoader.clearThreadLocalClear=To prevent a memory leak, the ThreadLocal has been forcibly removed.
webappClassLoader.clearThreadLocalFail=Failed to clear ThreadLocal references for web application [{0}]
webappClassLoader.stopThreadFail=Failed to terminate thread named [{0}] for web application [{1}]
webappClassLoader.stopTimerThreadFail=Failed to terminate TimerThread named [{0}] for web application [{1}]
private boolean clearReferencesStopThreads = false;
/**
+ * Should Tomcat attempt to clear any ThreadLocal objects that are instances
+ * of classes loaded by this class loader. Failure to remove any such
+ * objects will result in a memory leak on web application stop, undeploy or
+ * reload. It is disabled by default since the clearing of the ThreadLocal
+ * objects is not performed in a thread-safe manner.
+ */
+ private boolean clearReferencesThreadLocals = false;
+
+ /**
* Should Tomcat call {@link org.apache.juli.logging.LogFactory#release()}
* when the class loader is stopped? If not specified, the default value
* of <code>true</code> is used. Changing the default setting is likely to
}
+
+
+ /**
+ * Return the clearReferencesThreadLocals flag for this Context.
+ */
+ public boolean getClearReferencesThreadLocals() {
+ return (this.clearReferencesThreadLocals);
+ }
+
+
+ /**
+ * Set the clearReferencesThreadLocals feature for this Context.
+ *
+ * @param clearReferencesThreadLocals The new flag value
+ */
+ public void setClearReferencesThreadLocals(
+ boolean clearReferencesThreadLocals) {
+ this.clearReferencesThreadLocals = clearReferencesThreadLocals;
+ }
+
+
/**
* Set the clearReferencesLogFactoryRelease feature for this Context.
*
log.debug(sm.getString(
"webappClassLoader.clearThreadLocalDebug",
args));
+ if (clearReferencesThreadLocals) {
+ log.debug(sm.getString(
+ "webappClassLoader.clearThreadLocalDebugClear"));
+ }
}
} else {
log.error(sm.getString(
"webappClassLoader.clearThreadLocal",
args));
+ if (clearReferencesThreadLocals) {
+ log.info(sm.getString(
+ "webappClassLoader.clearThreadLocalClear"));
+ }
}
- if (key == null) {
- staleEntriesCount++;
- } else {
- mapRemove.invoke(map, key);
+ if (clearReferencesThreadLocals) {
+ if (key == null) {
+ staleEntriesCount++;
+ } else {
+ mapRemove.invoke(map, key);
+ }
}
}
}
((StandardContext) container).getClearReferencesStatic());
classLoader.setClearReferencesStopThreads(
((StandardContext) container).getClearReferencesStopThreads());
+ classLoader.setClearReferencesThreadLocals(
+ ((StandardContext) container).getClearReferencesThreadLocals());
}
for (int i = 0; i < repositories.length; i++) {
default value of <code>false</code> will be used.</p>
</attribute>
+ <attribute name="clearReferencesThreadLocals" required="false">
+ <p>If <code>true</code>, Tomcat attempts to clear any ThreadLocal
+ objects that are instances of classes loaded by this class loader.
+ Failure to remove any such objects will result in a memory leak on web
+ application stop, undeploy or reload. If not specified, the default
+ value of <code>false</code> will be used since the clearing of the
+ ThreadLocal objects is not performed in a thread-safe manner.</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