I'm stumped with this one:
I’m using the following:
Hibernate 3.5 with c3p0
Struts2
Tomcat 6.0.29
Java 6
I get an error indicating a memory leak whenever the webapp is reloaded without shutting down Tomcat completely. For example, I see the following when the webapp reloads in Eclipse:
Jan 29, 2011 11:20:50 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/MyApp] registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the
JDBC Driver has been forcibly unregistered.
Then I'll eventually see:
Exception in
thread "Timer-0" java.lang.NullPointerException
at com.mchange.v2.log.log4j.Log4jMLog$Log4jMLogger.isLoggable(Log4jMLog.java:255)
at com.mchange.v2.resourcepool.BasicResourcePool$CullTask.run(BasicResourcePool.java:1934)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
If I keep allowing the app to reload, I eventually run out of permagen memory.
When I reload the application using Tomcat Manager it fails to close JDBC connections, and they'll start to multiply.
Is there a way to ensure that all connections are closed and the driver unregistered whenever the application reloads?
My Hibernate configurations are shown below ...
Thanks for any help!
David
config.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
// Read in from properties file:
config.setProperty("hibernate.connection.url",
WebAppProperties.getProperty("db.host"));
config.setProperty("hibernate.connection.username",
WebAppProperties.getProperty("db.username"));
config.setProperty("hibernate.connection.password",
WebAppProperties.getProperty("db.password"));
config.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
config.setProperty("hibernate.connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider");
config.setProperty("hibernate.c3p0.min_size", "5");
config.setProperty("hibernate.c3p0.max_size", "20");
config.setProperty("hibernate.c3p0.timeout", "60");
config.setProperty("hibernate.c3p0.max_statements", "50");
config.setProperty("hibernate.c3p0.idle_test_period", "3000");
config.setProperty("hibernate.current_session_context_class", "thread");
config.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider");
config.setProperty("hibernate.hbm2ddl.auto",
WebAppProperties.getProperty("db.hbm2ddl"));