Reputation: 3515
I have a simple JSP Servlet web app currently deployed on Google App Engine. I have a SessionListener implementing HttpSessionListener to monitor creation and destroying of sessions.
public class SessionListener implements HttpSessionListener {
private int sessionCount = 0;
@Override
public void sessionCreated(HttpSessionEvent event) {
// TODO Auto-generated method stub
synchronized (this) {
sessionCount++;
}
System.out.println("Session Created: " + event.getSession().getId());
System.out.println("Total Sessions: " + sessionCount);
}
@Override
public void sessionDestroyed(HttpSessionEvent event) {
// TODO Auto-generated method stub
synchronized (this) {
sessionCount--;
}
System.out.println("Session Destroyed: " + event.getSession().getId() + ", " + event.getSession().getAttribute("loginName"));
System.out.println("Total Sessions: " + sessionCount);
}
}
In the web.xml file I have set the following config to allow automated session timeout after 30 minutes:
<session-config>
<session-timeout>30</session-timeout>
</session-config>
In the appengine-web.xml file I have set the following config:
<sessions-enabled>true</sessions-enabled>
When deployed and running locally sessions idle for 30 minutes get destroyed after 30 minutes as I could see in the console
"Session Destroyed: {sessionId} etc"
However when I got the app deployed on GAE I could not find the printout in the Log console of the GAE Admin page for the idle session. A session only gets destroyed when I explicitly hit the Logout button that calls
HttpSession session=request.getSession(false);
session.invalidate();
So I think idle sessions never get destroyed after the specific set time. And I could notice that the total count of sessions kept increasing with new browsers accessing the web app.
I know GAE deals with session their way: store sessions in the Datastore and share them throughout JVMs. However is there a way to make session timeout work and destroy the sessions idle for a period of time?
Upvotes: 2
Views: 1430
Reputation: 3515
Tweaking the GAE built-in SessionCleanupServlet solved the problem for me. More details: https://web.archive.org/web/20130708093908/http://www.radomirml.com/blog/2011/03/26/cleaning-up-expired-sessions-from-app-engine-datastore/
Upvotes: 3