OC4J 上的 setMaxInactiveInterval 不准确
我在 oc4j 端部署了一个 servlet 应用程序。
我试图在 1
分钟后使用以下方法使用户会话无效:
session.setMaxInactiveInterval(1 * 60);
但会发生什么情况是,在会话被销毁之前需要超过 1 分钟(并且可能达到 1 分半钟)。
这是一个实施问题还是什么?
I've a servlet app deployed in side oc4j.
I am trying to invalidate the user session after 1
minute using:
session.setMaxInactiveInterval(1 * 60);
But What happens is that It takes over 1 minute (and may reach 1 min and half) before the session get destroyed.
Is this an implementation issue, or what?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎是通过等待 HttpSessionListener#sessionDestoryed() 被调用来检查销毁,而不是在 1 分钟后实际向服务器发送 HTTP 请求。
大多数服务器上的会话销毁是由后台作业管理的,该作业每隔一段时间运行一次,可以是每分钟或更长时间,具体取决于服务器品牌/版本、配置以及可能的负载。该作业检查所有打开的会话是否已过期,并相应地清除过期会话。因此,只要客户端尚未发送请求,就不会在会话过期的同一秒立即调用会话销毁。此后台作业不会每秒运行,否则会占用大量 CPU 资源。
然而,只要服务器检索带有会话 ID 的请求,而会话仍然存在于服务器内存中但已过期,会话销毁就会立即被调用。
因此,您要么必须接受它,要么改变您的测试方法。
You seem to be checking the destroy by waiting until
HttpSessionListener#sessionDestoryed()
get called instead of actually sending a HTTP request to the server after exactly 1 minute.The session destroy is on most servers managed by a background job which runs at intervals, which can be each minute or more depending on server make/version, configuration and possibly also load. This job checks all open sessions whether it has been expired or not and sweeps the expired ones accordingly. Thus, it is not true that the session destroy is immediately called on the same second as the session is expired as long as the client hasn't sent a request. This background job does not run every second, it would have been too CPU intensive.
The session destroy will however be immediately called whenever the server retrieves a request with a session ID while the session is still present in server's memory but is been expired.
So, you'd either have to accept it or to change your testing methodology.