Tagged: tomcat

the JDBC Driver has been forcibly unregistered


My Tomcat instance keeps complaining about de-registration failures of JDBC drivers whenever my web app re-deployed.

The web application [some-fine-webapp] registered the JDBC driver [some.nasty.JdbcDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

This is actually not a problem. That message means that the Tomcat took care of something by himself.

I pay or I owe.

@WebListener
public class MyServletContextListener implements ServletContextListener {

    @Override
    public void contextInitialized(final ServletContextEvent sce) {
    }

    @Override
    public void contextDestroyed(final ServletContextEvent sce) {
        // Is this safe? De-registering while enumerating?
        for (final Enumeration<Driver> drivers = DriverManager.getDrivers();
             drivers.hasMoreElements();) {
            try {
                DriverManager.deregisterDriver(drivers.nextElement());
            } catch (final SQLException sqle) {
            }
        }
    }
}

Well, well, well.

Collections.list(DriverManager.getDrivers()).forEach(d -> {
    try {
        DriverManager.deregisterDriver(d);
    } catch (final SQLException sqle) {
    }
});

Shell script for restarting tomcat


References

startup/shutdown

There are two shell scripts for starting up and shutting down tomcat instance. The former is startup.sh and the latter is shutdown.sh.
It is not a big deal for making another shell script calls these two scripts in a row.

$ cat restart.sh
#!/bin/sh
sh ./shutdown.sh
sh ./startup.sh
$ 

The problem is that this script doesn’t run outside the directory contains the script. You can find a solution for this problem from the link above.

$ cat restart.sh
wd="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
sh $wd/shutdown.sh
sh $wd/startup.sh
$