Search code examples
javahttpsessionwildflyinvalidation

java httpSession invalidate while processing


Hy guys,

here's my problem. I have a servlet that answers incoming queries. 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? Or is it possible to cancel the invalidate of a session somehow?

The servlet runs on a Wildfly12.

I hope someone can help me. Many greetings


Solution

  • The timeout defined in web.xml is an idle session timeout. 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)...

    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 !