Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8651667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:07:39+00:00 2026-06-12T14:07:39+00:00

In my webapp, I created a service that is using an ExecutorService with fixed

  • 0

In my webapp, I created a service that is using an ExecutorService with fixed size ThreadPool. I reuse the same ExecutorService during the whole application lifetime.

private static ExecutorService pool = Executors.newFixedThreadPool(8);

All is running in Tomcat which gives me the following error while shuting down:

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.

I do realize I need to shutdown the ExecutorService before shuting tomcat down. Soms SO thread already speak about this but I could not find a clean way to handle this.

Should I use a ShutdownHook as suggested @Tim-bender in Graceful shutdown of threads and executor ? Or should I use a CachedThreadPool instead?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:07:40+00:00Added an answer on June 12, 2026 at 2:07 pm

    Shutdown hook is not a good approach in Tomcat because:

    • it will close the pool too late (on shutdown), Tomcat will already warn you about not closed resources

    • you actually want to shutdown that pool when application is undeployed so that redeployment works (otherwise each application will create new pool and they will all be closed only on complete shutdown)

    • shutting down the thread pool might take some time (see below), shutdown hook should be as fast as possible

    Much better place is ServletContextListener.contextDestroyed(). Remember you have to both shutdownNow() the pool (to cancel running and reject new tasks) and awaitTermination() to wait for already running tasks to finish and all threads to stop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a webapp using maven2 archetype in netbeans 6.7. when I do
So I created a new maven pom based webapp using intelliJ 11. Now I
I'm using jax-rs (jersey) to create a website / web-service that other users can
Scenario I have a Node.JS service (written using ExpressJS ) that accepts image uploads
Let's assume that I have created my REST service smoothly and I am returning
Suppose I created a custom web application that consists of: several assembly DLLs: web
I have a spring mvc application that I am using Hibernate with. I am
I've created a webapp for my thesis on my localhost. Now, when trying to
couple days ago I've created spring webapp with scalate template endine. Everything worked great
I have a quite specific problem. I created a webapp and want to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.