Unload event for Tomcat

Hello all,
I have an application that fails to unregister the MySql driver when I stop/unload it from Tomcat. I was wondering if there is any event/ method that triggers when the application (deployed on tomcat 6) is being stopped/unloaded, because I must deregister the MySql Driver by hand and I don't know where to put that code.

I'm afraid you need to explain what you mean by "unregister the SQL driver" and why you want to do it.

Best practice for JDBC on J2EE is that the mysql driver jar would be located in the TOMCAT_HOME/lib directory (NOT in the WAR!), and therefore the actual driver would be available for the life of the appserver, regardless of what webapps were deployed/undeployed.

Customer surveys are for companies who didn't pay proper attention to begin with.

Oct 5, 2010 2:41:42 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: A web application registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

Oct 5, 2010 2:41:42 PM org.apache.catalina.loader.WebappClassLoader clearReferencesStopTimerThread
SEVERE: A web application appears to have started a TimerThread named [MySQL Statement Cancellation Timer] via the java.util.Timer API but has failed to stop it. To prevent a memory leak, the timer (and hence the associated thread) has been forcibly cancelled.
Oct 5, 2010 2:41:42 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: A web application created a ThreadLocal with key of type [org.apache.axis.utils.XMLUtils.ThreadLocalDocumentBuilder] (value [org.apache.axis.utils.XMLUtils$ThreadLocalDocumentBuilder@1daf835]) and a value of type [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl] (value [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl@dd7404]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
Oct 5, 2010 2:41:42 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: A web application created a ThreadLocal with key of type [org.apache.axis.utils.XMLUtils.ThreadLocalDocumentBuilder] (value [org.apache.axis.utils.XMLUtils$ThreadLocalDocumentBuilder@1daf835]) and a value of type [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl] (value [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl@ebbf5c]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
Oct 5, 2010 2:41:42 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: A web application created a ThreadLocal with key of type [org.apache.axis.utils.XMLUtils.ThreadLocalDocumentBuilder] (value [org.apache.axis.utils.XMLUtils$ThreadLocalDocumentBuilder@1daf835]) and a value of type [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl] (value [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl@1606bf5]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
Oct 5, 2010 2:41:42 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: A web application created a ThreadLocal with key of type [org.apache.axis.utils.XMLUtils.ThreadLocalDocumentBuilder] (value [org.apache.axis.utils.XMLUtils$ThreadLocalDocumentBuilder@1daf835]) and a value of type [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl] (value [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl@14fcc96]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
log4j:ERROR LogMananger.repositorySelector was null likely due to error in class reloading, using NOPLoggerRepository. [code]

I am using Tomcat 6.
I was thinking that I should manually remove the driver (it is placed in the WAR) because it fails to do so by itself (don't know why). I heard that Tomcat 7 does that automatically.

You're not using a database connection pool. J2EE is an expensive technology, so you might as well take full advantage of it, and one of those advantages is pooled database resources. As I said, it's not best practice to include a JDBC driver in a WAR. Aside from losing the considerable benefits of connection pooling, it binds you to one specific brand of database, and while I certainly see enough people who can never escape MS SQL Server (thanks to over-use of stored procedures), I personally prefer a little more freedom. You can never tell when the boss may come in and say "We're switching database vendors".

You also have some Apache Axis resources that are dangling around loose.

The PermGenSpace error is a hallmark of redeploying a running webapp. And yes, Tomcat 7 is supposed to make that better, but Tomcat 7 is still in Beta. And it's sufficiently different from Tomcat6 that not all of our favorite toolkits are certified for it yet.

Andrei Antonescu
Ranch Hand

Joined: Jul 08, 2010
Posts: 75

posted Nov 13, 2010 03:39:06

0

Hello,
Thank you very much for the info. I will use a connection pool to solve the first problem.
You are right.On the same server I also have a WebService installed (build using Axis). I have created 2 instances of tomcat so that the apps won't cause problems one to another.
I have installed a profiler and realised that I don't really know how to investigate what Axis resources are causing problems.
Can you please give me any hints?