简体   繁体   English

java httpSession在处理时无效

[英]java httpSession invalidate while processing

Hy guys, 大家好

here's my problem. 这是我的问题。 I have a servlet that answers incoming queries. 我有一个Servlet,可以回答传入的查询。 A session is opened for each request. 将为每个请求打开一个会话。 This session has a lifetime of one minute. 该会话的生命周期为一分钟。 Now it can be that a new request comes exactly at the moment where the session expires. 现在可能是一个新请求正好在会话到期时发出。 This request runs exactly into the session invalidate. 该请求正好在会话无效中运行。 At the beginning of the request the session is still valid, at the end not any more. 在请求开始时,会话仍然有效,在结束时不再有效。 Accordingly there is then an exception. 因此,存在一个例外。

My question now is, is there a way to dynamically extend the session in Wildfly? 我现在的问题是,有没有办法在Wildfly中动态扩展会话? Or is it possible to cancel the invalidate of a session somehow? 还是可以通过某种方式取消会话的无效?

The servlet runs on a Wildfly12. 该servlet在Wildfly12上运行。

I hope someone can help me. 我希望有一个人可以帮助我。 Many greetings 许多问候

The timeout defined in web.xml is an idle session timeout. web.xml中定义的超时是空闲会话超时。 If you set it to one minute, this does not mean your session has a lifetime of one minute, it means that it will be invalidated after one minute of inactivity ! 如果将其设置为一分钟,这并不意味着您的会话的生命周期为一分钟,这意味着一分钟的不活动状态将使该会话无效! This is a major difference. 这是一个主要区别。

Saying that " at the beginning of the request the session is still valid, at the end not any more " is very strange because, if the request is being processed, it means some current activity which is a bit in contradiction with an idle state (NB: ok, you may get a read timeout if your servlet does not respond within a reasonable delay to the requester, but that's another story, nothing to see with session)... 说“ 在请求开始时会话仍然有效,在结束时不再有效 ”是很奇怪的,因为如果正在处理请求,则意味着当前的某些活动与空闲状态有些矛盾(注意:好的,如果您的servlet在合理的延迟内未响应请求者,则可能会导致读取超时,但这是另外一回事了,在会话中看不到)。

Now if you really want extend timeout for current session, you can do it programatically: 现在,如果您真的想延长当前会话的超时时间,则可以通过编程方式进行:

HttpSession session = request.getSession();
session.setMaxInactiveInterval(10*60); // in seconds !

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

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