gpt4 book ai didi

java - 在 Java servlet 中终止请求花费的时间太长

转载 作者:搜寻专家 更新时间:2023-11-01 02:36:27 32 4
gpt4 key购买 nike

我有一个简单的 Java Servlet 应用程序正在运行。它有几个端点。尽管服务速度非常快,但我收到的一些请求有时会比预期花费更多的时间。杀死任何处理时间超过 20 秒的请求的最佳方法是什么?

最佳答案

如果你想中断请求处理线程并且你正在使用 Tomcat,你可以尝试 Stuck Thread Detection Valve :

interruptThreadThreshold

Minimum duration in seconds after which a stuck thread should be interrupted to attempt to "free" it.

Note that there's no guarantee that the thread will get unstuck. This usually works well for threads stuck on I/O or locks, but is probably useless in case of infinite loops.

Default is -1 which disables the feature. To enable it, the value must be greater or equal to threshold.

实现Circuit Breaker可能会更好在客户端中,interruptThreadThreshold 不能保证适用于所有场景。

关于java - 在 Java servlet 中终止请求花费的时间太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49500116/

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