For a Java JSP web application I’m making, I keep an object in a session.
If there are multiple users signed onto the site, each in their own session, I would like for all the session (regardless of when they started) to expire at midnight the same day.
For instance:
session object 1: creation date (2012-12-11 8:45), expiration date (2012-12-12 0:00)
session object 2: creation date (2012-12-11 12:00), expiration date (2012-12-12 0:00)
And so on, every day the day’s sessions getting invalidated.
Some ideas I had was
- to set the session’s time until expiration to (the next midnight – the current date), though I’m not entirely confident in my ability to progrematically do this
- schedule some kind of server task to clear all the sessions at midnight every day
What is the best way to go about this?
The best way I see is Option 2
Option 1 is also possible but might be little unpredictable as you have to set a precise timeout every time you create a new session.
Have fun !