Session can die in following three ways in J2EE application:
- Its Time out
- invalidate() method called on Session Object
- Application goes down (Application crashes or undeployed)
Method 1: Configuring session timeout in the DD
Session Time out can be configured in DD (Deployment Descriptor / web.xml) and it has virtually same effect as calling setMaxInactiveInterval() on every session that is created :
<web-app> ... <servlet> .... </servlet> <session-config> <session-timeout>15<session-timeout> </session-config> </web-app>
Note : Argument in tag is in minutes. In above example its 15 minutes.
Method 2: Setting Session timeout for the specific session object
If you want to change the session timeout for any particular session then we can call below method on that Session :
session.setMaxInactiveInterval(30*60);
Note : the argument passed in method setMaxInactiveInterval() is in seconds. In Above example its 30 minutes.
Leave a Reply