Tomcat6線程池的配置

第一步,打開共享的線程池

<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="1000" minSpareThreads="50" maxIdleTime="600000"/>
默認前後是註釋<!-- -->掉的,去掉就可以了。其中

name
The name used to reference this pool in other places in server.xml. The name is required and must be unique.
這個是線程池的名字,必須唯一,我們在後面的配置裏要用到這個東西

namePrefix
(String) The name prefix for each thread created by the executor. The thread name for an individual thread will be namePrefix+threadNumber
線程的名字前綴,用來標記線程名字的,這樣每個線程就用這個前綴加上線程編號了,比如
catalina-exec-1
catalina-exec-2

maxThreads
(int) The max number of active threads in this pool, default is 200
允許的最大線程池裏的線程數量,默認是200,大的併發應該設置的高一些,反正只是限制而已,不佔用資源

minSpareThreads
(int) The minimum number of threads always kept alive, default is 25
最小的保持活躍的線程數量,默認是25.這個要根據負載情況自行調整了。太小了就影響反應速度,太大了白白佔用資源。

maxIdleTime
(int) The number of milliseconds before an idle thread shutsdown, unless the number of active threads are less or equal to minSpareThreads. Default value is 60000(1 minute)
超過最小活躍線程數量的線程,如果空閒時間超過這個設置後,會被關別。默認是1分鐘。

threadPriority
(int) The thread priority for threads in the executor, the default is Thread.NORM_PRIORITY
線程的等級。默認是Thread.NORM_PRIORITY


第二步
在 Connector裏指定使用共享線程池

 

<Connector
port="8009"
protocol="AJP/1.3"
maxThreads="5000"
executor="tomcatThreadPool"
注意,一旦使用了線程池,則其它的線程屬性,比如 maxThreads等將被忽略

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章