I have a tomcat 7 running on a low memory CentOS. Currently it has 2 connectors for ports 80 and 443. Important configuration options are:

<Connector port="80" protocol="HTTP/1.1" executor="tomcatThreadPool"

<Connector port="443" protocol="HTTP/1.1" executor="tomcatThreadPool"
                SSLEnabled="true" scheme="https" secure="true"

Both connectors is bound to an executor:

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
                maxThreads="100" minSpareThreads="3"
                maxIdleTime="120000" />

When tomcat is first started, it starts about 50 threads. After about 15-20 users connecting to web application, it is increased to about 60. (I count tomcat threads with command ps -eLf | grep java |grep tomcat |wc -l)

I have about 4 connections per minute, it is not more than 5 due to the nature of my application. Therefore I want tomcat to start minimum possible threads. Since I have configured minimum of 3 spare threads and keepalive as 2 minutes, it should not go over 20 or something. But I am wrong.

How can I limit the number of Tomcat threads to a minimum value like 20 or 30?


According to this documentation the number of minimum threads can be configured using the following parameter:

Attribute Description
minSpareThreads(int) The minimum number of threads always kept alive, default is 25

According to this documentation it could be implemented as follows:

<Connector port="8080" address="localhost"     
     minSpareThreads="20" />

At server startup, the HTTP Connector will create a number of processing threads based on the value configured for the minSpareThreads attribute.

  • I used an executor and defined minSpareThreads but it does work. Should I use just connector and define minsparethreads? As answered here executor allows to share a thread pool by connectors stackoverflow.com/questions/9626211/… – jdiver Nov 14 '14 at 20:58
  • @jdiver did you restart Tomcat after changing the server.xml? – 030 Nov 14 '14 at 21:01
  • Of course; I keep restart tomcat once each 2 days because it consumes all memory. – jdiver Nov 14 '14 at 21:02
  • Ok that is interesting. Do you use a tool like JVisualVM to investigate the threads? Which tools are you using? I assume that you are using certain tools as you provide information regarding the amount of threads in the question. – 030 Nov 14 '14 at 21:03
  • I just restarted now and there are 52 threads. Actually I don't understand why it is starting about 50 threads each time. – jdiver Nov 14 '14 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.