tomcat线程数

测试tomcat线程数:

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="2" minSpareThreads="1" maxQueueSize="1"/>
<Connector port="8080"  executor="tomcatThreadPool" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"  URIEncoding="UTF-8"/>
<Connector  executor="tomcatThreadPool" port="8009" protocol="AJP/1.3" redirectPort="8443" />
启用的协议是apr协议。因为我用了executor属性,官方文档中对Connector标签中的executor属性是这么说的:



A reference to the name in an Executor element. If this attribute is set, and the named executor exists, the connector will use the executor, and all the other thread attributes will be ignored. Note that if a shared executor is not specified for a connector then the connector will use a private, internal executor to provide the thread pool.

如果用了executor属性,那么所有其他的thread的属性将会被忽略。所以此时我们只有看Executor标签,来设置executor标签中的属性:


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


maxQueueSize

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


如果我的executor标签中不设置maxQueneSize属性,那么默认的为int的最大值,意思就是:如果我不设置这个,那么请求数在达到Integer.MAX_VALUE之前是不会被拒绝的,都会放在队列里面等待执行。

如果我按照上面的配置,最小存活数是1,最大活跃线程数是2,队列里面最大是1,那么当我们重启tomcat的时候,第一次去请求会发现一共只有3个请求线程被执行(2+1),剩下的请求都会被tomcat直接reject拒绝掉,如果你去捕获异常,会发现抛出如下错误:

警告: Socket processing request was rejected for:469001312
java.util.concurrent.RejectedExecutionException: Work queue full.
at org.apache.catalina.core.StandardThreadExecutor.execute(StandardThreadExecutor.java:172)
at org.apache.tomcat.util.net.AprEndpoint.processSocketWithOptions(AprEndpoint.java:882)
at org.apache.tomcat.util.net.AprEndpoint$Acceptor.run(AprEndpoint.java:1088)
at java.lang.Thread.run(Thread.java:745)


一月 10, 2017 2:59:34 下午 org.apache.tomcat.util.net.AprEndpoint processSocket
警告: Socket processing request was rejected for:468993104
java.util.concurrent.RejectedExecutionException: Work queue full.
at org.apache.catalina.core.StandardThreadExecutor.execute(StandardThreadExecutor.java:172)
at org.apache.tomcat.util.net.AprEndpoint.processSocket(AprEndpoint.java:913)
at org.apache.tomcat.util.net.AprEndpoint$Poller.run(AprEndpoint.java:1973)
at java.lang.Thread.run(Thread.java:745)
socket请求被拒绝,直接返回502错误。

当我们再次用多线程去请求的时候,发现此时就不一定只有3个线程可用了,会发现基本上都会大于3个?(why)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值