Saturday, October 1, 2011

Solved two mysql+tomcat problems

Solved two mysql+tomcat problems:

1. The web application registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web.
2. The web application appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed.


1. The web application registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web.

PROBLEM:
org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/rest] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web


SOLUTION:
http://stackoverflow.com/questions/3320400/jdbc-driver-unregisted-when-the-web-application-stops

import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class JdbcListener implements ServletContextListener
{
private static final Logger LOG = Logger.getLogger(JdbcListener.class);

public void contextDestroyed(ServletContextEvent sce)
{
deregisterJdbcDriver();
}

public void contextInitialized(ServletContextEvent sce)
{

}

private void deregisterJdbcDriver()
{
// This manually deregisters JDBC driver, which prevents Tomcat 7 from complaining about memory leaks
Enumeration drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements())
{
Driver driver = drivers.nextElement();
try
{
DriverManager.deregisterDriver(driver);
LOG.info(String.format("Deregistering jdbc driver: %s", driver));
}
catch (SQLException e)
{
LOG.info(String.format("Error deregistering driver %s", driver), e);
}
}
}

}




2. The web application appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed.

PROBLEM:
org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/rest] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed


SOLUTION:
http://bugs.mysql.com/bug.php?id=36565
To upgrage mysql connector jar.
http://dev.mysql.com/downloads/connector/j/

     
mysql
mysql-connector-java
5.1.17

1 comment:

Caine Mutiny said...

Thank you. This was very helpful.