gpt4 book ai didi

Tomcat 应该中止卡住的上传线程

转载 作者:行者123 更新时间:2023-11-28 22:51:56 25 4
gpt4 key购买 nike

我检查了 Tomcat 的文档,但没有找到任何配置选项:让我们简化 tomcat HTTP 线程可以拥有的状态数量:就绪、连接、服务、完成

在没有流量的情况下,所有的http-threads都会有status=ready。如果有客户端请求,状态会切换到 Connecting,然后切换到 Service。如果所有字节都可以传送到客户端,则最后会有一个简短的 Finishing 状态。之后,线程切换回就绪状态,为新请求做好准备。

如果上传(在状态服务中)卡住,我的意思是在 10 秒内没有发送任何字节,我可以告诉 Tomcat 中止这些线程吗?

我没有找到可以完全做到这一点的选项。有什么提示吗?

最佳答案

有两个配置选项:

  • 连接超时:

The number of milliseconds this Connector will wait, after accepting a connection, for the request URI line to be presented. Use a value of -1 to indicate no (i.e. infinite) timeout. The default value is 60000 (i.e. 60 seconds) but note that the standard server.xml that ships with Tomcat sets this to 20000 (i.e. 20 seconds). Unless disableUploadTimeout is set to false, this timeout will also be used when reading the request body (if any).

  • 连接上传超时

Specifies the timeout, in milliseconds, to use while a data upload is in progress. This only takes effect if disableUploadTimeout is set to false.

  • 保持事件超时

The number of milliseconds this Connector will wait for another HTTP request before closing the connection. The default value is to use the value that has been set for the connectionTimeout attribute. Use a value of -1 to indicate no (i.e. infinite) timeout.

来源:https://tomcat.apache.org/tomcat-7.0-doc/config/http.html

如果你想在写入客户端时防止阻塞,那么你应该使用异步 servlet 并将写入操作封装在 Hystrix 命令中。

关于Tomcat 应该中止卡住的上传线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37188151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com