Tomcat 6.0 共享線程池的配置Shared Executor Thread pool(注:轉載于http://www.java2000.net/p11864)
配置很簡單
第一步,打開共享的線程池
- <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等將被忽略
我測試了一下,由于每次請求不再需要重新分配線程,系統響應速度還是有很明顯的改善的。
posted on 2010-09-09 09:53 小一敗涂地 閱讀(2324) 評論(0) 編輯 收藏 所屬分類: tomcat、apache、jboss等服務器相關