• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jdbc connections not closing

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"));
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, David!
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure the two issues are related to the final premgen error but I'll proceed.

The first issue is related to the DB driver being loaded by the webapp and not removing it when the webapp stops. This is not related to closing a particular connection, it is just the Driver. You can implement a ContextListener to remove the Driver but personally it has never caused me any issues.

For the second, calls to Log4J are thread safe, but you can still get strange errors when using Log4J in multi threaded environments. One cause for this is that another thread results in a logging call but the logging includes a Class that was unloaded by the container during the shutdown or redeploy. A suggested solution is to use Apache commons-logging or slf4j to abstract the logging behaviour but I haven't tried it explicitly and not 100% it works.

As for the last part, the actual premgen error, sometimes that can just be a case of not having enough pergen space allocated, but in your case does sound like a memory leak. I have seen the same behaviour using Liferay 5.2 but not in Liferay 6 (in case you're using this) but other than that you could look at the Eclipse based Memory Analysis Tool to grab a memory dump and see if you can find the problem.

and Welcome to the Ranch
 
David Alt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, there's definitely a memory leak when it reloads in Eclipse. I get the following:

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.
Jan 30, 2011 8:42:51 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/MyApp] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.
Jan 30, 2011 8:42:51 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/MyApp] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] but has failed to stop it. This is very likely to create a memory leak.
Jan 30, 2011 8:42:51 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/MyApp] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] but has failed to stop it. This is very likely to create a memory leak.
Jan 30, 2011 8:42:51 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads

Tomcat Manager also shows that there has been a memory leak upon redeploy.

-David
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm experiencing exactly the same issue, was any solution found here?
 
David Alt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't have one yet. I haven't had a chance to dig into it with a profiler, and so I just restart the server whenever I release. Sorry...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any updates on this?

We have a very small Tomcat 6.0.32, Spring 3.0.3, Hibernate 3.2.6, c3p0 0.9.1.2 configuration.

Datasources are configured to shutdown when Spring goes down.

We are sure that the host is not leaking as it loads and free huge amount of data for weeks with no change in memory usage.

Still, when shut down we see the trace above for the potential memory leak.

Thanks,

David Zonsheine
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic