0

I'm seeing the following error during Tomcat shutdown:

Jan 04, 2015 4:14:31 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [] registered the JDBC driver [org.apache.derby.jdbc.AutoloadedDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

I understand Tomcat forcibly unregistered the driver to prevent a memory leak.

However, how to fix and who is responsible for fixing this issue -- me, Tomcat DBCP, or Derby?

I'm using Tomcat 7.0.47 and Derby 10.11.1.1

context.xml for Tomcat:

<Context>
  <Resource name="jdbc/db" auth="Container" type="javax.sql.DataSource"
               driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
               factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
               maxActive="100"
               minIdle="2"
               maxIdle="30"
               maxWait="10000"
               validationQuery="VALUES 1"
               testOnBorrow="true"
               removeAbandoned="true"
               url="jdbc:derby:dev;create=true"
               username="root"
               password="root"
               />
</Context>

Similar questions I found on Google referenced DERBY-4895, but that issue has been fixed a while ago.

3

1 Answer 1

0

You can simply ignore it, or you can create a ServletContextListener that deregisters the drivers at app shutdown:

public class MyContextListener implements ServletContextListener{

 @Override
 public void contextDestroyed(ServletContextEvent arg0) {
    System.out.println("App shutdown ...");

    System.out.println("Deregistering SQL-Drivers ...");
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        Driver driver = drivers.nextElement();
        try {
            DriverManager.deregisterDriver(driver);
            System.out.println(driver.getClass().getName());
        } catch (SQLException e) {
            System.err.println("Error deregistering driver " + driver.getClass().getName());
        }
    }
 }

 @Override
 public void contextInitialized(ServletContextEvent arg0) {
 }
}

Of course you need to add the listener to your web.xml, or annotate it with @WebListener.

2
  • In your opinion, who should be fixing this issue. Should I fix it or wait for a proper fix from Derby and/or Tomcat DBCP?
    – Victor L
    Jan 5, 2015 at 13:46
  • This warnings exist for years now, I would suggest you to fix it manually.
    – Stefan
    Jan 5, 2015 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.