tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Thomas <>
Subject Re: Weblogic library and Tomcat
Date Wed, 11 Feb 2009 12:52:38 GMT
Pieter Temmerman wrote:

> First of all, I'm not sure how I can figure out where the references to
> the prior instances are being maintained, and secondly, I don't know how
> to clean them up (both are closely related if you ask me :-) )

You are on the right track with a profiler. I use (and highly recommend)
YourKit. I get a free copy as an Apache developer for investigating Tomcat
related issues but it is reasonably priced and I have bought several copies for
different projects over the years. It usually returns the investment on the
first issue I fix.

As to the why - image a scenario such as this.

Tomcat starts
Tomcat (for some reason) loads a JDBC driver
The JDBC driver is registered with the driver manager
Note: Tomcat has to load the DriverManager to do this
Your webapp starts
Your web app loads a JDBC driver
Your web app registered the JDBC driver with the driver manager
Your web app stops
You have a huge memory leak.

Remembering that every class keeps a reference to the classloader that loaded it:
DriverManager was loaded by Tomcat
DriverManager has a reference to your JDBC driver
Your JDBC driver has a reference to the web application classloader
The web application class loader retains references to every class it has loaded

Hence none of your classes are unloaded and Tomcat has an instance of your web
application it can't garbage collect -> memory leak.

Repeat this a few times and you'll get an OOM.

As well as JDBC drivers, logging frameworks are frequent culprits for causing this.

> My first thought was to take thread dumps, but there aren't showing up
> any previous instances of the webapp.
> I don't have any experience with profilers, but I can try to use
> VisualVM (which has a profiler-like tab) to take a look at all the
> objects being instantiated. 
> Say I find any references to Weblogic, how should I go about having them
> removed automatically each time the application is being redeployed?

You need to find which objects are holding on to a reference to the the weblogic
class and make sure it gets cleared when the app restarts. A context listener
might be useful here.

In the example above, you would need to remove the reference to your JDBC driver
from the DriverManager.

Profilers should provide utilities to trace references to instances of classes.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message