How to close Java Threads in servlets

Hi,

I am getting this warning in an java servlet application which is deployed on tomcat. I am creating threads to do scheduled task execution. But I am not destroying/stopping the threads in any part of the code as I don't know what't the best way to handle it in servlets without crashing the whole application or tomcat.

Please help how to prevent memory leaks so that I can run the app forever without being forced to restart the app all the time

thanks
-anshu



Nov 16, 2015 4:52:20 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/abcd1234] has started
Nov 16, 2015 4:52:20 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
SEVERE: The web application [/abcd1234] appears to have started a thread named [pool-1-thread-1] but has failed to stop it. This is very likely to create a memory leak.
Nov 16, 2015 4:52:22 PM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Nov 16, 2015 4:52:22 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/abcd1234] is completed
anshumaEngineeringAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

anshumaEngineeringAuthor Commented:
mccarlIT Business Systems Analyst / Software DeveloperCommented:
You just need to shutdown your executor.... m_executor.shutdown()  when your servlet is being removed, so potentially in a "destroy()" method of your servlet.

See the docs here https://docs.oracle.com/javaee/7/api/javax/servlet/Servlet.html#destroy--

And if the above is not obvious, post your code and we can help further.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
This is in reference to the following question

http://www.experts-exchange.com/questions/28808959/How-to-create-java-threads-with-multiple-start-and-run-signatures.html
Are you sure it's not more apt to quote THIS one?
anshumaEngineeringAuthor Commented:
thank you experts
mccarlIT Business Systems Analyst / Software DeveloperCommented:
You're welcome!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.