Tomcat優化系列-配置tomcatThreadPool

在tomcat中每一個用戶請求都是一個線程,所以可以使用線程池提高性能。

配置線程池

修改server.xm
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

參數說明

在這裏插入圖片描述

threadPriority (優先級)

(int) The thread priority for threads in the executor, the default is 5 (the value of theThread.NORM_PRIORITY constant)

daemon(守護進程)

(boolean) Whether the threads should be daemon threads or not, the default is true

namePrefix(名稱前綴)

(String) The name prefix for each thread created by the executor. The thread name for an individual thread will be namePrefix+threadNumber

maxThreads(最大線程數)

(int) The max number of active threads in this pool, default is 200

minSpareThreads(最小活躍線程數)

(int) The minimum number of threads always kept alive, default is 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)

maxQueueSize(最大的等待隊裏數,超過則請求拒絕)

(int) The maximum number of runnable tasks that can queue up awaiting execution before we reject them. Default value is Integer.MAX_VALUE

prestartminSpareThreads(是否在啓動時就生成minSpareThreads個線程)

(boolean) Whether minSpareThreads should be started when starting the Executor or not, the default is false

threadRenewalDelay(重建線程的時間間隔)

(long) If a ThreadLocalLeakPreventionListener is configured, it will notify this executor about stopped contexts. After a context is stopped, threads in the pool are renewed. To avoid renewing all threads at the same time, this option sets a delay between renewal of any 2 threads. The value is in ms, default value is 1000 ms. If value is negative, threads are not renewed.
。重建線程池內的線程時,爲了避免線程同時重建,每隔threadRenewalDelay(單位: ms )重建一個線程。默認值爲1000 ,設置爲負則不重建

配置例子

在這裏插入圖片描述

發佈了125 篇原創文章 · 獲贊 24 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章