Search code examples
javagoogle-app-enginegoogle-cloud-datastorehttpsession

Google App Engine how to track httpsession destroy


anybody knows how to track httpsession destroy with GAE? I've found that HttpSessionListener doesn't work properly in GAE and sessionDestroyed method never calls.

To be more specific I have an information that I store in database when user logins to the application, but if some user is inactive for some time I need to remove this info from db, that will be easy if sessionDestroyed method will be invoked when such event happens, as for now I did cron job which runs each minute, the job queries all data of this kind handles in memory which data is inactive and removes it. But this is very inefficient way to do this, I can optimize it with cache. But maybe thare is some other elegant way.

Any thoughts are warmly appricated.


Solution

  • As you observe, HttpSessionListener doesn't work on App Engine, so this isn't possible. This is in part due to the fact that App Engine apps run multiple instances on multiple machines, so there's no single VM to invoke this on. Running a regular cleanup script as you describe is the best way to do this, though there's really no reason to run it every minute - a couple of times a day should be perfectly sufficient!