加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Tomcat 7.0.32 Spring MVC Servlet 3 Async无法正常工作

发布时间:2020-12-15 01:49:36 所属栏目:大数据 来源:网络整理
导读:我编写了非常简单的控制器,测试Servlet 3的功能: @Autowired ThreadPoolTaskExecutor taskExecutor; @RequestMapping(value="{name}",method = RequestMethod.GET) public @ResponseBody DeferredResult 在单独的线程中,我只做了5秒的睡眠命令,之后我将MyRe

我编写了非常简单的控制器,测试Servlet 3的功能:

@Autowired
    ThreadPoolTaskExecutor taskExecutor;

    @RequestMapping(value="{name}",method = RequestMethod.GET)
    public @ResponseBody DeferredResult

在单独的线程中,我只做了5秒的睡眠命令,之后我将MyResult POJO返回给DeferredResult.

我的web.xml文件符合Servlet 3规范:


我的连接器tomcat如下:

 

现在这是有趣的部分.当运行打开10个并发连接的简单程序时,我看到第一个集合被释放后,首先只提供5个连接,然后提供第二个5个连接(您可以从时间步进中看到它).这不是Servlet 3.0应该如何表现的

Fri May 31 01:17:57 IDT 2013: Preparing 10 concurrent connections
Fri May 31 01:18:02 IDT 2013: Output from Server int thread 9 :{"props1":"param1","props2":"param1"}
Fri May 31 01:18:02 IDT 2013: Output from Server int thread 8 :{"props1":"param1","props2":"param1"}
Fri May 31 01:18:02 IDT 2013: Output from Server int thread 4 :{"props1":"param1","props2":"param1"}
Fri May 31 01:18:02 IDT 2013: Output from Server int thread 7 :{"props1":"param1","props2":"param1"}
Fri May 31 01:18:02 IDT 2013: Output from Server int thread 2 :{"props1":"param1","props2":"param1"}
Fri May 31 01:18:07 IDT 2013: Output from Server int thread 1 :{"props1":"param1","props2":"param1"}
Fri May 31 01:18:07 IDT 2013: Output from Server int thread 0 :{"props1":"param1","props2":"param1"}
Fri May 31 01:18:07 IDT 2013: Output from Server int thread 5 :{"props1":"param1","props2":"param1"}
Fri May 31 01:18:07 IDT 2013: Output from Server int thread 6 :{"props1":"param1","props2":"param1"}
Fri May 31 01:18:07 IDT 2013: Output from Server int thread 3 :{"props1":"param1","props2":"param1"}

如果将Tomcat Connector更改为

   

它就像魅力一样.我不想这样做.根据Tomcat文档,我应该在没有Http11NioProtocol连接器的情况下接收Servlet 3.0功能.

怎么了?

最佳答案
问题是由于Tomcat配置中的maxThreads = 5设置.

对于非NIO情况,此设置不仅限制请求处理线程的最大数量,还限制最大连接数!

由于您尚未指定maxConnections,因此它正在为maxConnections选择默认值.
以下是Tomcat doc关于如何选择maxConnections的默认值的摘录:

maxConnections : The maximum number of connections that the server
will accept and process at any given time. When this number has been
reached,the server will not accept any more connections until the
number of connections falls below this value. The operating system may
still accept connections based on the acceptCount setting. Default
value varies by connector type. For BIO the default is the value of
maxThreads
unless an Executor is used in which case the default will
be the value of maxThreads from the executor. For NIO the default is
10000
. For APR/native,the default is 8192.

您可以显式指定maxConnections =“10”(例如)设置以覆盖此默认行为.然后,您应该看到无论使用哪种连接器,都可以获得10个并行请求.我试过这个并且它有效.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读