You need to set the session timeout, that is, the time after which the current Session object will be invalidated.
This can be done either by setting a timeout in your web.xml, for example:
<session-config> <session-timeout>20</session-timeout> </session-config>
or programmatically call a Session object
session.setMaxInactiveInterval(valueInSeconds);
Make sure that the session timeout period set in web.xml is in minutes and programmatically in seconds.
source share