简体   繁体   中英

“Temporarily” set session timeout for method - setMaxInactiveInterval

In my web application a user can call a long running backend service (synchronous request). The execution time for this service should not count for the websession timeout so in my code i tried:

handleUserRequest() {
  HttpSession session = ...getSession(false);
  int oldMaxInactiveInterval = session.getMaxInactiveInterval();
  session.setMaxInactiveInterval(BIG_VALUE);
  <LONG RUNNING TASK>
  session.setMaxInactiveInterval(oldMaxInactiveInterval);
}

This is not working as expected. The temporary session timeout is not recognized for this "method call". The user session times out according to the oldMaxInactiveInterval value.

Is it possible to do, what I want to do? ;-)

If your oldMaxInactiveInterval defaultsession-timeout is defined in web.xml for example 60. means it's 60 minutes. when you will set using session#setMaxInactiveInterval() It will be always in second(1 mimnute)

It sets the default session timeout for the web app

<session-config>
    <session-timeout>60</session-timeout> // 60 minutes
</session-config>

Calling session.setMaxInactiveInterval() sets the timeout for the particular session it is called on, and overrides the default.

Remember this difference, too - the deployment descriptor version uses minutes, and session.setMaxInactiveInterval() uses seconds.

session.setMaxInactiveInterval(300); // Its sets the 5 minutes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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