1

I'm building a web app with j2ee, hibernate and Spring. At a certain point the app has to send a number of emails, so I thought of putting this task in a separate thread. Details:

  • There is syncronization on a number of status variables the thread and the controller share
  • There is NOT synchronization on the service bean that is shared with the controller (should it be?).

Anyway, when I shut down the app, I receive the following worrying message:

...
INFO: Closing Hibernate SessionFactory
25-mar-2011 10.02.14 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
GRAVE: The web application [/Tomcat6Locale] registered the JDBC driver [org.hsqldb.jdbc.JDBCDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
25-mar-2011 10.02.14 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
GRAVE: The web application [/Tomcat6Locale] registered the JDBC 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.
25-mar-2011 10.02.14 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
GRAVE: The web application [/Tomcat6Locale] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak.
25-mar-2011 10.02.15 org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080

That I was not getting before the thread trick... In the end when one of these threads completes, they just return. I don't do anything special. Should I do more?

gotch4
  • 13,093
  • 29
  • 107
  • 170

2 Answers2

0

The message seems very clear. You are failing to clean up after yourself. And that's what the other thread suggested by Tomasz talks about.

Now on to solution:

The quick and dirty:

Clean up your threadlocals!

What I would recommend:

If your email sending is really a different tasks and not synchronous have you considered implementing a scheduler instead of doing it through a thread? From the sounds of it what you are looking for is that emails can be sent in asynchronous manner. If you have the option of changing things I would recommend you to separate the 2 processes and employ a scheduler to perform email sender function.

Hope that helps.

Nilesh
  • 4,137
  • 6
  • 39
  • 53
0

I disagree with Nilesh's assessment. The container is supposed to manage the database connection pool when it is specified as a Resource. Assuming you close all the connections you get, you should be fine ... in theory.

I have heard that the fault is with Apache's DBCP library. I've also heard that it has been fixed in newer versions of DBCP, although it seems like a version of Tomcat should have shipped by now. Anyway, manually upgrading DBCP to the latest version is something to try.

NOTE: My answer applies to the JDBC driver related parts of the message. The message that says "appears to have started a thread named ..." may or may not be fixed by fixing the JDBC driver problems.

Pixel
  • 374
  • 5
  • 15