我有一个运行在低内存CentOS上的tomcat 7。 目前它有2个连接器用于端口80和443.重要的configuration选项是:
<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"
这两个连接器都绑定到执行程序:
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="100" minSpareThreads="3" maxIdleTime="120000" />
当tomcat第一次启动时,它启动大约50个线程。 经过大约15-20个用户连接到Web应用程序,它增加到约60.(我使用命令ps -eLf | grep java |grep tomcat |wc -l计算tomcat线程)
我每分钟有4个连接,由于我的应用程序的性质,它不超过5个。 所以我想要tomcat启动尽可能less的线程。 由于我configuration了最less3个备用线程并保持2分钟,所以不应该超过20个。 但是我错了。
我如何限制Tomcat线程的数量为20或30的最小值?
根据此文档 ,可以使用以下参数configuration最小线程数:
Attribute Description
minSpareThreads (int) The minimum number of threads always kept alive, default is 25
根据这个文件可以实现如下:
<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.