Centos – How to limit the number of Tomcat threads

centosthreadstomcat7

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"
                connectionTimeout="10000"
                keepAliveTimeout="60000"

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

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?

Best Answer

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.