Tomcat优化系列-配置tomcatThreadPool

在tomcat中每一个用户请求都是一个线程,所以可以使用线程池提高性能。

配置线程池

修改server.xm
Tomcat优化系列-配置tomcatThreadPool
Tomcat优化系列-配置tomcatThreadPool
Tomcat优化系列-配置tomcatThreadPool

参数说明

Tomcat优化系列-配置tomcatThreadPool

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 ,设置为负则不重建

配置例子

Tomcat优化系列-配置tomcatThreadPool