在Java servlet中杀死请求太久的请求
作者:互联网
我有一个简单的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,servlets,java-threads 来源: https://codeday.me/bug/20190622/1262758.html