• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unload event for Tomcat

 
Andrei Antonescu
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks in advance
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When Tomcat removes a servlet instance, the javax.servlet.Servlet destroy() method is guaranteed to be called.

As per the JavaDocs, this is the programmer's chance to clean up resources.

Bill
 
Andrei Antonescu
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,
Thank you all for posting. The error I am getting is:

[code]
INFO: HTMLManager: stop: Stopping web application at '/WebAppName'



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]


After a while I am getting


Exception in thread "http-2020-3" java.lang.OutOfMemoryError: PermGen space


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.

Andrei
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic