【问题标题】:jetty: dynamically changing idle timejetty:动态改变空闲时间
【发布时间】:2025-11-22 23:20:03
【问题描述】:

我有一个码头服务器,它被配置为在 30 秒后过期请求,这是 xml 配置文件中的配置行:

<Set name="maxIdleTime">30000</Set>

此服务器接受两种请求:必须实时处理的请求和来自批处理脚本的请求,这些请求可能需要一些时间才能得到答复。

一个请求预计最多需要几分钟。 现在我想让这个请求在不超时的情况下完全执行,同时保持“正常”实时请求的到期时间较短,以避免潜在的拥塞。

我的猜测是我必须这样做:

public class MyServlet extends HttpServlet {

    ...

    public void doGet(HttpServletRequest pRequest, HttpServletResponse pResponse)
        throws IOException, ServletException {

        if (pRequest is of the type allowed to be slow) {
            set max idle time for this request very high (or infinite)
        }

        server.execute(pRequest, pResponse);
    }


}

我正在使用码头 6.1.2rc4

【问题讨论】:

    标签: java servlets jetty


    【解决方案1】:

    maxIdleTime 参数不配置允许请求占用的时间。当 Jetty 决定收缩池时,该值用于从线程池中移除空闲线程。请参阅 QueuedThreadPool#setMaxIdleTime() 的 javadoc。

    如果请求超时,可能是由于一侧或两侧的套接字超时参数。

    【讨论】:

    • 谢谢,我误解了那个参数。现在我会注意套接字问题