tomcat_home_directory/conf/server.xml中:
tomcat
配置:
<!-- 自定義一個線程池:name -->
<!-- 屬性: -->
<!-- name:線程池的名稱 -->
<!-- namePrefix:線程池中線程名的前綴,默認爲catalina-exec-(注:tomcat線程池中線程的名稱爲:前綴+線程number) -->
<!-- maxThreads:線程池中容許建立的最大線程數,默認是200 -->
<!-- minSpareThreads:線程池中保持的最小線程數(即線程池中的corePoolSize),默認是10。 -->
<!-- maxIdleTime:空閒線程被關閉的超時時間,默認是60000毫秒,即1分鐘。(注:只有當前活躍的線程數大於minSpareThreads時,tomcat纔會去關閉空閒的線程) -->
<!-- maxQueueSize:線程池中任務隊列的容量,默認爲Integer.MAX_VALUE -->
<!-- prestartminSpareThreads:是否在啓動時就生成minSpareThreads個線程,默認是false -->
<Executor name="tomcatThreadPool"
namePrefix="catalina-exec-"
maxThreads="1000"
minSpareThreads="100"
maxIdleTime=300000
maxQueueSize="100000"
prestartminSpareThreads="false"
/>
<!-- 配置Connector -->
<!-- 屬性: -->
<!-- executor:指定使用的線程池。 -->
<!-- 注意:1>若是不配置線程池,則tomcat會使用一個默認的鏈接池。 -->
<!-- 2>若是指定了Connector的executor,則Connector其它的線程相關的屬性將被忽略。 -->
<!-- URIEncoding:編碼格式,tomcat8默認使用utf-8,tomcat7默認使用ISO-8859-1。 -->
<!-- maxConnections:tomcat能夠同時處理的最大請求數(即有多少個socket能夠同時鏈接到tomcat上),即tomcat的最大併發數。對於NIO的默認值是10000,對於APR/native的默認值是8192。 -->
<!-- acceptCount:請求隊列的容量,默認值是100。注意區分這裏的請求等待隊列和線程池中的任務等待隊列。 -->
<!-- 說明: -->
<!-- 1>當處理請求的線程數達到最大(即處理請求的線程數爲maxThreads) 或 請求的數量達到maxConnections時,若是還有請求進來,則將請求放到一個容量爲acceptCount的等待隊列中,若等待隊列已滿,則tomcat會拒絕掉新的請求。 -->
<!-- 2>(The maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused. The default value is 100.) -->
<!-- acceptorThreadCount:用於接收鏈接請求的線程的數量,默認爲1。(The number of threads to be used to accept connections. Increase this value on a multi CPU machine) -->
<!-- enableLookups:Set to true if you want calls to request.getRemoteHost() to perform DNS lookups in order to return the actual host name of the remote client. Set to false to skip the DNS lookup and return the IP address in String form instead (thereby improving performance). By default, DNS lookups are disabled -->
<!-- disableUploadTimeout:是否禁用數據上傳超時限制,默認爲true -->
<!-- connectionUploadTimeout:上傳數據的超時時間,單位是毫秒,只有當disableUploadTimeout爲false時纔有效。 -->併發
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="utf-8"
acceptorThreadCount="2"
enableLookups="false"
disableUploadTimeout="true"
acceptCount="1000"/>
socket