Registered the JDBC driver [Oracle.jdbc.driver.OracleDriver] but failed to unregister it when the

Source: Internet
Author: User
Tags tomcat


Serious: the Web application [/testweb] registered the JDBC driver [Oracle.jdbc.driver.OracleDriver] but failed to unregister I t when the Web application is stopped. To prevent a memory leak, the JDBC Driver has been, forcibly.

Google Answers

Since version 6.0.24, Tomcat ships with a memory leak detection feature, which in turn can leads to this kind of warning me Ssages when there's a JDBC 4.0 compatible driver in the WebApp ' S/web-inf/lib the which auto-registers itself during ' s The startup using the Serviceloader API, but which did not auto-deregister itself during WebApp ' s shutdown. This is purely informal, TOMCAT has already taken the memory leak action prevention.

What can you do?

Ignore those warnings. The Tomcat is doing it job right. The actual bug is in someone else's code (the JDBC driver in question) and not in yours. Be happy this Tomcat did its job properly and wait until the JDBC driver vendor get it fixed so this you can upgrade the D River.

Downgrade to Tomcat 6.0.23 or older so, you are not is bothered with those warnings. But It'll silently keep leaking memory. Not sure if is good to know after all. Those kind of memory leaks are one of the major causes behind OutOfMemoryError issues Tomcat during.

Move the JDBC driver to Tomcat ' S/lib folder and have a connection pooled datasource to manage the driver. Note This Tomcat ' s builtin DBCP does not deregister drivers to close. Also bug DBCP-322. The DBCP project is however currently stalling. I wouldn ' t expect quick updates. You are would rather like to replace DBCP by another connection pool which it job doing better then. For example BONECP or Tomcat JDBC Pool maybe?


I found that implementing a simple Destroy () method to de-register any JDBC drivers works nicely.
/**
 * Destroys the servlet cleanly by unloading JDBC drivers.
 * 
 * @see Javax.servlet.genericservlet#destroy () * */public
void Destroy () {
    String prefix = getclass (). Getsimplename () + "destroy ()";
    ServletContext CTX = Getservletcontext ();
    try {
        enumeration<driver> drivers = drivermanager.getdrivers ();
        while (Drivers.hasmoreelements ()) {
            drivermanager.deregisterdriver (drivers.nextelement ());
        }
    } catch (Exception e) {
        ctx.log (prefix + "Exception caught while deregistering JDBC drivers", e);
    }
    Ctx.log (prefix + "complete");
}

I'll add to this something I found on the Spring forums. If you move your JDBC driver jar to the Tomcat Lib folder, instead of deploying it with your webapp, the warning seems to Disappear. I can confirm this is worked for me

http://forum.springsource.org/showthread.php?87335-Failure-to-unregister-the-MySQL-JDBC-Driver&p=334883# post334883


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.