Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A web application appears to have started a thread named [22] but has failed to stop it. This is very likely to create a memory leak

I have a web application with Servlets in the back end deployed over tomcat. The application is simple java application.

I see this error frequently in the server logs: SEVERE: A web application appears to have started a thread named [22] but has failed to stop it. This is very likely to create a memory leak.

Are there any potential reasons which might be causing it?

like image 932
rl99 Avatar asked May 05 '11 23:05

rl99


3 Answers

I'd use visualvm 1.3.2 and see what threads are being created. Be sure to add all the plug-ins.

If it's not being done by your code you won't have much control over it.

You also don't know if the message is a red herring or not. Load test your code over a period of time and measure what happens.

like image 112
duffymo Avatar answered Nov 19 '22 01:11

duffymo


I faced similar situation recently Resolved in below steps

  1. I took Thread dump. ( using Kill -QUIT pid )
  2. Found the Runnable/Thread class form dump
  3. Then i put a debug point in run method and started application in debug mode.
  4. Got the code which starts My Thread and I observed it was not stopped while stoping application.
  5. Introduced code to stop the thread in contextDestroyed method of AppContextListener (This is My application class which extends ServletContextListener ) as this method will be called when i stop tomcat.

If you set Thread as Dameon Thread it is not going to help , you can visit explanation.

like image 22
Vipin Avatar answered Nov 19 '22 01:11

Vipin


Tomcat waits for all the application's threads (user threads not daemon threads) to stop before it goes down, I guess that in your case this specific thread is a user thread and therefore tomcat generated this error. I suggest you to change this thread to daemon (assuming this one is yours)

like image 1
Guy Avatar answered Nov 19 '22 03:11

Guy