You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/02/12 18:50:22 UTC
svn commit: r909526 -
/tomcat/trunk/java/org/apache/catalina/core/StandardHost.java
Author: markt
Date: Fri Feb 12 17:50:22 2010
New Revision: 909526
URL: http://svn.apache.org/viewvc?rev=909526&view=rev
Log:
Make class loader registration more robust
Modified:
tomcat/trunk/java/org/apache/catalina/core/StandardHost.java
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardHost.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardHost.java?rev=909526&r1=909525&r2=909526&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardHost.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardHost.java Fri Feb 12 17:50:22 2010
@@ -30,7 +30,10 @@
import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Host;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleException;
+import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Valve;
import org.apache.catalina.loader.WebappClassLoader;
import org.apache.catalina.startup.HostConfig;
@@ -579,17 +582,33 @@
throw new IllegalArgumentException
(sm.getString("standardHost.notContext"));
super.addChild(child);
-
- // Record a reference to the context's class loader to aid memory leak
- // detection
- if (child.getLoader() != null) {
- childClassLoaders.put(child.getLoader().getClassLoader(),
- child.getName());
+
+ if (child instanceof Lifecycle) {
+ ((Lifecycle) child).addLifecycleListener(
+ new MemoryLeakTrackingListener());
}
}
/**
+ * Used to ensure the regardless of {@link Context} implementation, a record
+ * is kept of the class loader used every time a context starts.
+ */
+ private class MemoryLeakTrackingListener implements LifecycleListener {
+ @Override
+ public void lifecycleEvent(LifecycleEvent event) {
+ if (event.getType().equals(Lifecycle.AFTER_START_EVENT)) {
+ if (event.getSource() instanceof Context) {
+ Context context = ((Context) event.getSource());
+ childClassLoaders.put(context.getLoader().getClassLoader(),
+ context.getServletContext().getContextPath());
+ }
+ }
+ }
+ }
+
+
+ /**
* Attempt to identify the contexts that have a class loader memory leak.
* This is usually triggered on context reload. Note: This method attempts
* to force a full garbage collection. This should be used with extreme
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org