2

Tomcat increases the number of threads from minSpareThreads to maxThreads step by step.

What is the trigger that makes Tomcat increase the number of threads?

Johnny Lim
  • 5,623
  • 8
  • 38
  • 53

1 Answers1

2

It's probably slightly different than you write:

  • minThreads: The number of threads that are allocated on startup
  • minSpareThreads: The number of threads that should be available at all time. If less are available (idle), increase their number until maxThreads is reached
  • maxThreads: Never have more than this number of threads running at the same time.

(I have to admit, I didn't look up the documentation - and you didn't say if this applies to HTTP threads, database threads or others, but this is what I'm used to see)

Sample: Let say you have configured 10 / 5 / 20 threads (min, minSpare, max). On startup, 10 threads will be added to the pool. For the first 5 consumed threads, nothing else happens. Once the 6th thread is consumed, you have less than 5 spare threads and this is the reason to start up more (until this condition is met again).

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • For the curious, this works by applying a sort of "queue capacity hack" over the standard threadpool components. Normally, a standard java threadpool won't add more threads unless the queue is totally full. The implementation here hacks around that: https://github.com/apache/tomcat/blob/bed0e0297c863e39d29fc0a523013b8f0fd65bfa/java/org/apache/tomcat/util/threads/TaskQueue.java#L72-L83 – jocull Jun 08 '20 at 13:54