File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Expiring session data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Expiring session data" Watch "Expiring session data" New topic
Author

Expiring session data

Michael J. Makunas
Ranch Hand

Joined: Mar 11, 2002
Posts: 37
Is there a way to make objects that are stored in the session "expire" after a set amount of time even though the session is still valid? I know I could add some sort of time stamp to the data structure and check that timistamp the next time I retrieve the object from the session. What I really want is for these objects to remove themselves after a certain amount of time.
Scott Dunbar
Ranch Hand

Joined: Sep 23, 2004
Posts: 245
There isn't a standard that addresses this. If you want individual objects to timeout at a different time than the session you'll have to do some sort of custom coding to remove them.

Perhaps you can use the session getLastAccessedTime() and flush out "semi-old" objects as needed. That is, maybe your overall session timeout is 30 minutes. But on a request you could look at the session and check to see if it has been accessed within the last 15 minutes. If so, you would toast the objects that you want. This could be done in a Filter which would then be transparent to your servlets. Just a thought.


<a href="http://forums.hotjoe.com/forums/list.page" target="_blank" rel="nofollow">Java forums using Java software</a> - Come and help get them started.
Michael J. Makunas
Ranch Hand

Joined: Mar 11, 2002
Posts: 37
Hmmmm....I've heard about filters but I've never used them before. I just did a quick search on them and they look really useful for some other things I'm doing. Thanks for the idea!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

That's almost exactly what we do: use a filter to check a timestamp in a session token.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Naveen Garg
Greenhorn

Joined: Oct 07, 2004
Posts: 2
Use session.setMaxInactiveInterval(time in miliseconds) methods to set the time a session should exists.

Originally posted by Michael J. Makunas:
Is there a way to make objects that are stored in the session "expire" after a set amount of time even though the session is still valid? I know I could add some sort of time stamp to the data structure and check that timistamp the next time I retrieve the object from the session. What I really want is for these objects to remove themselves after a certain amount of time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Expiring session data
 
Similar Threads
valueUnbound() not getting called
Hi , I need advice how return to client large amount of data
Releasing HTTP session state
Storing Large Data to Auto Generated Data Files
Session Replication