简体   繁体   English

Java-会话超时限制的可行性

[英]Java- feasibility of session timeout limit

Is it feasible to set unlimited session time out programmatically using HttpSession. setMaxInactiveInterval(int seconds) 使用HttpSession. setMaxInactiveInterval(int seconds)以编程方式设置无限会话超时是否可行HttpSession. setMaxInactiveInterval(int seconds) HttpSession. setMaxInactiveInterval(int seconds) or using HttpSession. setMaxInactiveInterval(int seconds)或使用

<session-config>
    <session-timeout>-1</session-timeout>
</session-config>

? Will this lead to any overhead? 这会导致任何开销吗?

Yes. 是。 It is possible to programmatically set the session timeout via a java servlet or jsp page using the setMaxInactiveInterval method, 可以使用setMaxInactiveInterval方法通过java servlet或jsp页面以编程方式设置会话超时,

HttpSession.setMaxInactiveInterval(int seconds) HttpSession.setMaxInactiveInterval(int秒)

Here the int value in seconds specifies the time, in seconds, between client requests before the servlet container will invalidate this session. 这里的int值(以秒为单位)指定了servlet容器使该会话无效之前客户端请求之间的时间(以秒为单位)。

An interval value of zero or less indicates that the session should never timeout. 间隔值等于或小于零表示会话永不超时。

However, many HTTP servers in general use are configured to drop persistent connections after a certain period of inactivity in order to conserve system resources, quite often without informing the client. 但是,为了节省系统资源,许多常用的HTTP服务器被配置为在一段时间不活动后丢弃持久连接,以节省系统资源,而通常不会通知客户端。 So keeping up the connectins alive may lead to java.lang.OutOfMemoryError: GC overhead limit exceeded error. 因此,保持connectins处于活动状态可能会导致java.lang.OutOfMemoryError: GC overhead limit exceeded错误。

Out Of Memory Error 内存不足错误

More open connections requires more memory and more requests hit your server and eventually causes your server to crash. 更加开放的连接需要更多的内存,并且更多的请求到达您的服务器,最终导致服务器崩溃。

The documentation says that calling that method with a negative number of seconds will cause the session to never time out. 该文档说,以负秒数调用该方法将导致会话永不超时。

Overhead depends on the implementation, but I suppose (as can be seen in the source code for Catalina's StandardSession) it would cause less overhead than a limited session time, because the server does not need to do the cleanup required after the expiry time. 开销取决于实现,但是我想(从Catalina的StandardSession的源代码中可以看出),它将导致比有限的会话时间更少的开销,因为服务器不需要在到期时间之后进行所需的清理。

Through config file is preferred, Reason being able to change timeout limit in one place if the question is whether to go with config file or calling setMaxInactiveInterval(int seconds) within code. 首选通过配置文件,如果问题是使用配置文件还是在代码内调用setMaxInactiveInterval(int seconds),则可以在一处更改超时限制的原因。

And yes we can set unlimited timeout limit through config settings. 是的,我们可以通过配置设置设置无限超时限制。

答案就在这篇文章中: http : //www.theserverside.com/discussions/thread.tss? thread_id= 26490服务器将耗尽内存

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM