0

tomcat(3)线程池

 2 years ago
source link: https://wakzz.cn/2018/04/15/tomcat/(3)%E7%BA%BF%E7%A8%8B%E6%B1%A0/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

2、修改配置

2.1、添加连接池配置

修改conf/server.xml,添加线程池申明:

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>

2.2、修改连接器配置

为连接器添加executor属性,值为连接池配置的name值。

<Connector executor="tomcatThreadPool" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000"
redirectPort="8443" />

如图所示:

这里写图片描述

3、Executor参数

配置信息详见http://127.0.0.1:8080/docs/config/executor.html
|属性|描述|
|–|–|
|threadPriority|(int)执行程序中线程的线程优先级,默认值是 5(Thread.NORM_PRIORITY常量的值)|
|daemon|(boolean)线程是否应该守护线程,默认是 true|
|namePrefix|(字符串)执行程序创建的每个线程的名称前缀。单个线程的线程名称将为namePrefix+threadNumber|
|maxThreads|(int)此池中活动线程的最大数量,默认为 200|
|minSpareThreads|(int)线程的最小数量始终保持活动状态,默认为 25|
|maxIdleTime|(int)空闲线程关闭前的毫秒数,除非活动线程数小于或等于minSpareThreads。默认值是60000(1分钟)|
|maxQueueSize|(int)在我们拒绝它们之前可以排队等待执行的最大可运行任务数。默认值是Integer.MAX_VALUE|
|prestartminSpareThreads|(boolean)启动Executor时是否启动minSpareThreads,默认值是 false|
|threadRenewalDelay|(long)如果配置了ThreadLocalLeakPreventionListener,它将通知此执行程序有关停止的上下文。上下文停止后,池中的线程会被更新。为避免同时更新所有线程,此选项设置更新任何2个线程之间的延迟时间。该值以毫秒为单位,默认值为1000毫秒。如果值为负数,线程不会被更新。|

4、推荐配置

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="800" minSpareThreads="100" maxQueueSize="100" prestartminSpareThreads="true" />

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK