views:

1105

answers:

3

I am getting this message when I run my web application. It runs fine but I get this message during shutdown.

SEVERE: A web application registered the JBDC driver [oracle.jdbc.driver.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

Any help appreciated.

+5  A: 

Since version 6.0.24, Tomcat ships with a memory leak detection feature, which in turn can lead to this kind of warning messages. This particular message is caused by Tomcat's builtin DBCP not deregistering drivers properly on close. See also bug DBCP-322. This message is purely informal, Tomcat has already taken the memory leak prevention action accordingly.

What can you do?

  1. Ignore those warnings. Tomcat is doing its job right. The actual bug is in someone else's code, not in yours. Be happy that Tomcat did its job properly and wait until the DBCP guys get it fixed so that you can upgrade.

  2. Downgrade to Tomcat 6.0.23 or older so that you will not be bothered with those warnings. But it will silently keep leaking memory. Not sure if that's good to know after all.

  3. Decorate BasicDataSource#close() so that it is deregistering the driver properly. Also see the code example in the above link to DBCP-322 bug.

  4. Replace DBCP by another connection pool which is doing its job better then DBCP. For example C3P0 or Tomcat JDBC Pool maybe?

BalusC
This is good advice. It's not warning of a memory leak, it's a warning that Tomcat took some forcible action to prevent a leak
matt b
Thanks a lot....
mona
+1 - Awesome answer.
duffymo
@BalusC, we are not using Tomcat's connection pool, do you think the message should still show up??
mona
Then the connection pool which you're using has the same problem as DBCP. It is not deregistering the driver properly on shutdown.
BalusC
can we keep it this way or do you suggest to use the fix shown in DBCP-322 that you provided in the answer? I was wondering if we could just ignore those warnings! Thanks for your quick responses...
mona
I posted 4 possible solutions. It's up to you. It at least doesn't harm.
BalusC
A: 

BalusC: this has nothing to do with pools and whatever. This is purely driver registration/deregistration issue in mysql`s driver or tomcats webapp-classloader. Copy mysql driver into tomcats lib folder (so its loaded by jvm directly, not by tomcat), and message will be gone. That makes mysql jdbc driver to be unloaded only at JVM shutdown, and noone cares about memory leaks then.

sick old bastard
A: 

I was having a similar problem, but additionally I was getting a Java Heap Space error anytime I modified/saved JSP pages with Tomcat server running, therefore the context were not fully recharged.

My versions were Apache Tomcat 6.0.29 and JDK 6u12.

Upgrading JDK to 6u21 as suggested in References section of URL http://wiki.apache.org/tomcat/MemoryLeakProtection solved the Java Heap Space problem (context now reloads OK) although JDBC Driver error still appears.

nihcap