一、發現問題
info: maximum number of threads (200) created for connector with address null and port 8080
說明:最大線程數錯誤
解決方案:使用線程池,用較少的線程處理較多的通路,可以提高tomcat處理請求的能力。
二、使用方法
打開/conf/server.xml增加
<executor name="tomcatthreadpool" nameprefix="catalina-exec-"
maxthreads="500" minsparethreads="20" maxidletime="60000" />
最大線程500(一般伺服器足夠),最小空閑線程數20,線程最大空閑時間60秒。接着修改<connector>節點,增加executor屬性。
<connector executor="tomcatthreadpool"
port="80" protocol="http/1.1"
connectiontimeout="60000"
keepalivetimeout="15000"
maxkeepaliverequests="1"
redirectport="443" />
三、linux中檢視檔案操作數
java.net.socketexception: too many open files。當tomcat并發使用者量大的時候,單個jvm程序确實可能打開過多的檔案句柄。使用lsof -p 10001|wc -l檢視檔案操作數。
1、ps -ef |grep tomcat
檢視tomcat的程序id,記錄id号,假設程序id為10001
2、lsof -p 10001|wc -l
檢視目前程序id為10001的檔案操作數
3、ulimit -a
檢視每個使用者允許打開的最大檔案數預設是1024
4、ulimit -n 65536
将允許的最大檔案數調整為65536