0

Every time I start and stop tomcat service I get following info in tomcat-stderr.log file:

SEVERE: The web application [/twinkle] registered the JDBC driver [net.sourceforge.jtds.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.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] 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.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] 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.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] but has failed to stop it. This is very likely to create a memory leak.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#3] but has failed to stop it. This is very likely to create a memory leak.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#4] but has failed to stop it. This is very likely to create a memory leak.
Mar 01, 2016 2:02:00 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/twinkle] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#5] but has failed to stop it. This is very likely to create a memory leak.
Mar 01, 2016 2:02:01 AM org.apache.catalina.startup.HostConfig undeploy
INFO: Undeploying context [/twinkle]

Our application is crashing on production all the time and I was thinking that this could be one of few reasons if not the primary cause of it.

In our application I noticed many places where we create new Thread object;

FTPClient.java

217  Thread.sleep(5);
443  try { Thread.sleep(5); }
     catch( InterruptedException ie) {}
557  Thread.sleep(5);
576  Thread.sleep(1);

ConnectionPool.java

 private Thread m_CleanupThread = null; 
    protected ConnectionPool(String urlString, String user, String passwd) 
    {
       ...
       m_CleanupThread = new Thread(this); 
       m_CleanupThread.start();
    } 

And many many more calls to Thread like this.

Should I use thread.setContextClassLoader(null);

Angelina
  • 2,175
  • 10
  • 42
  • 82
  • from the stacktrace this seems messed up. shouldn't you be using tomcat's connection pool and not defining your own in the application? – Nathan Hughes Mar 01 '16 at 17:51

2 Answers2

2

If you restart Tomcat then these memory-leak warnings will not be the cause of the crashing. The memory-leak warnings are relevant when you redeploy a web-application without restarting Tomcat because then Tomcat will keep eating memory without the option to use it or free it (zombie memory usage) which in turn leaves less memory for your web-application (and Tomcat) to use.

As for the "Could not locate driver class" error: have a close look at this answer and also make sure the web-application itself no longer contains the "jdbc.jar". In addition, set the appropriate options for c3p0 (set privilegeSpawnedThreads to true and set contextClassLoaderSource to library).

You might also want to try deleting Tomcat's work directory after stopping Tomcat and before starting Tomcat.

Community
  • 1
  • 1
vanOekel
  • 6,358
  • 1
  • 21
  • 56
1

For the Driver error, check this answer.

As specified in this Tomcat doc (Threads spawned by webapps paragraph) make sure you don't start any thread from application code.

This might happen explicitly (Thread # start) or implicitly e.g. using a Timer or an ExecutorService

You definitely don't want to do that : thread.setContextClassLoader(null), this just tries to hide the issue from Tomcat.

About the cleanup thread, marking them as daemon won't help unless you stop the whole container (the JVM). What you can do is having a ServletContextListener registered and in its contextDestroyed method stop all thread you started by interrupting them or changing some boolean flag they depend on (if implemented correctly they should provide some mechanism for stopping them).

Community
  • 1
  • 1
Bax
  • 4,260
  • 5
  • 43
  • 65