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

  • SEARCH
  • Home
  • 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 6234309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:27:44+00:00 2026-05-24T10:27:44+00:00

I am running a multi-threaded Java web application on Apache Tomcat 6. Instead of

  • 0

I am running a multi-threaded Java web application on Apache Tomcat 6. Instead of using the new Thread(); anti-pattern, I leave thread instantiation to Tomcat (see code below).

I noticed in the last days that the web application gets slower and slower. After restarting the servlet container everything is back to normal.

Since I am not terminating threads after processing them (Don’t know if I have to or if the Garbage Collector will destroy them), I am guessing that this is the cause for the performance loss.

The code basically looks like this:

Custom Server Listener (I added this to web.xml):

public class MyTaskRunner implements ServletContextListener {
  public static final ExecutorService EXECUTOR_SERVICE = ExecutorService.newFixedThreadPool(10000);

  public void contextDestroyed(ServletContextEvent sce) {
    EXECUTOR_SERVICE.shutdownNow();
  }
  public void contextInitialized(ServletContextEvent sce) {
  }
}

Thread instantiation:

for (Object foo : bar){
    MyTaskRunner.EXECUTOR_SERVICE.submit(new Runnable() {
      public void run() {
        doSomethingWith(foo);
    });
}

So, is there anything special that I have to do after run() has finished?

  • 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-05-24T10:27:45+00:00Added an answer on May 24, 2026 at 10:27 am

    Some basic facts about threads and GC:

    • While a thread is running, it will not be garbage collected.

    • When a thread is terminated, its stack is deleted and its Thread object is removed from the ThreadGroup data structures. The remainder of the threads’ state is subject to the normal reachability rules.

    • You don’t need to do anything special to make a thread terminate. It happens when the run method call ends, either because it returned, or because it exited with an (uncaught) exception.


    Now to your particular problem. Many things could be causing your performance degradation. For instance:

    • Some of your threads may be getting stuck; e.g. waiting on a lock, waiting for a notify that isn’t going to arrive, or just stuck in an infinite CPU loop.

    • You may have too many threads running (doing useful, or semi-useful things), and the slowdown may be a result of lock contention, CPU resource starvation, or thrashing.

    • You may have a memory leak of some kind, and the slowdown may be a symptom of your application starting to run out of heap space.

    To figure out what is going on, you are going to need to do some performance monitoring:

    • Look at the OS level stats to see if the application is thrashing.

    • Use a memory profile to see if your application is short of memory. If it is, see if there is a memory leak, and track it down.

    • Use a performance profiler to see if there are particular hotspots, or if there is a lot of lock contention.


    I agree with the comment. A thread pool size of 10000 is dangerously large. It should be a small constant multiplied by the number of cores available to your application.

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

Sidebar

Related Questions

Here's the scenario: I have a multi threaded java web application which is running
How can I do remote debugging of a multi threaded Python application, running on
I am running Sql Server Compact Edition 3.5.1.0 SP1 in a multi-thread application. The
I'm developing a long-running multi-threaded Python application for Windows, and I want the process
I have a multi-threaded application that is using pthreads. I have a mutex() lock
I am writing a multi-threaded application in Java in order to improve performance over
I have a multi-threaded application with (4) thread i want to know how much
I have a multi-threaded application build in C# using VS2010 Professional. It's quite a
I am getting a NullReferenceException when running my multi-threaded application, but only when I
I have a multi-threaded application which scales well to begin with, but running on

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.