当前位置: 代码迷 >> XML/SOAP >> Tomcat配置文件server.xml中connector的参数minSpareThreads跟maxSpareThreads
  详细解决方案

Tomcat配置文件server.xml中connector的参数minSpareThreads跟maxSpareThreads

热度:9856   发布时间:2013-02-26 00:00:00.0
Tomcat配置文件server.xml中connector的参数minSpareThreads和maxSpareThreads
在网上看到很多tomcat6.0的优化文章中,都提到了在server.xml中的connector标签中,加上minSpareThreadsmaxSpareThreads属性,可是我到了tomcat的官网上去看文档,发现tomcat6.0中connector标签根本没有这两个属性,在tomcat5.5中才有。
tomcat5.5的文档连接:http://tomcat.apache.org/tomcat-5.5-doc/config/http
里面原文是这样介绍这两个属性的:
maxSpareThreads:The maximum number of unused request processing threads that will be allowed to exist until the thread pool starts stopping the unnecessary threads. The default value is 50.
自己翻译一下,不知道是否正确:
maxSpareThreads:直到线程池开始停止不需要的线程时,允许存在空闲请求处理线程的最大数量。默认值50.
我的理解是这样的,当空闲的线程超过maxSpareThreads时,tomcat就关闭超出这个数值的线程。
网上的说法都是复制粘贴的,如下:
maxSpareThreads:最大备用线程数,一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程。
我觉得和我的理解是不同的。

再说,minSpareThreads。
minSpareThreads:The number of request processing threads that will be created when this Connector is first started. The connector will also make sure it has the specified number of idle processing threads available. This attribute should be set to a value smaller than that set for maxThreads. The default value is 4.
大概意思就是:初始会建立的线程数,并且确保最少会有这么多个线程数可用,并且设定的值要比参数maxThreads大。默认值是4.

以上是tomcat5.5的文档写的内容,到了tomcat6.0,文档里面根本就没有介绍这两个参数,难道是写文档的人落了这两个参数没有写?文档地址如下:
http://tomcat.apache.org/tomcat-6.0-doc/config/http
可是网上都说tomcat6.0优化要写这两个参数,是为什么???

到了tomcat7.0的时候,只有minSpareThreads了。文档地址如下:
http://tomcat.apache.org/tomcat-7.0-doc/config/http
tomcat7.0对minSpareThreads的介绍也发生了变化:
minSpareThreads:The minimum number of threads always kept running. If not specified, the default of 10 is used.
大家可以看到,默认值是10个了。

所以大家可否分享一下各自的知识,tomcat6.0究竟是有没有这两个参数呢?
1 楼 kevinwqw 昨天  
6.0确实没有这两个参数。我在http://blog.csdn.net/lifetragedy/article/details/7708724曾经指出过这个问题,但现在看不到我的回复了。
用了这两个参数,会出现警告。那篇博客的15楼回复,指出了一个解决办法,可供参考。
  相关解决方案