• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unload event for Tomcat

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?


 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic