Tomcat 请求超时 [英] Tomcat request timeout

查看:51
本文介绍了Tomcat 请求超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Web 应用程序中,有些请求持续时间超过 20 秒.但在某些情况下,代码可能会导致无限循环或类似情况,从而降低服务器速度.

In my web application there are some requests which last longer than 20 seconds. But in some situations the code can lead to infinite loop or something similar which slows down the server.

我想在服务器端设置一个 60 秒的请求超时.这是在tomcat中实现的吗?

I want to put a request timeout for 60 sec on the server side. Is this implemented in tomcat?

推荐答案

使用 Tomcat 7,您可以添加 StuckThreadDetectionValve 这将使您能够识别卡住"的线程.您可以在要检测的应用程序的 Context 元素中设置阀门:

With Tomcat 7, you can add the StuckThreadDetectionValve which will enable you to identify threads that are "stuck". You can set-up the valve in the Context element of the applications where you want to do detecting:

<Context ...>
  ...
  <Valve 
    className="org.apache.catalina.valves.StuckThreadDetectionValve"
    threshold="60" />
  ...
</Context>

这会将一个 WARN 条目写入 tomcat 日志中的任何需要超过 60 秒的线程,这将使您能够识别应用程序并禁止它们,因为它们有问题.

This would write a WARN entry into the tomcat log for any thread that takes longer than 60 seconds, which would enable you to identify the applications and ban them because they are faulty.

基于源代码 您可以编写自己的阀门来尝试停止线程,但这会对线程池产生影响,并且有 没有可靠的方法在没有该线程合作的情况下在Java中停止线程......

Based on the source code you may be able to write your own valve that attempts to stop the thread, however this would have knock on effects on the thread pool and there is no reliable way of stopping a thread in Java without the cooperation of that thread...

这篇关于Tomcat 请求超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆