I've only really been concerned with such a thing in one instance, and that was because we were caching some returned ResultSets, and they could be very large... What I wound up doing is wrapping each ResultSet in a HashMap, and I had two other elements, one storing the datetime stamp the object was created, and another specifying how long the object shoud live... Then, on every subsequent request I would check those values and null out any object older than it's specified time to live. It's not the most elegant solution, but the usage pattern of this particular application made it rather effective.

I also considered starting a daemon thread when the app started up that would periodically do cleanup chores, but I never got around to doing the research to see if it could gain access to the session information. I've used daemon threads in a number of cases for periodic tasks when I wanted the tasks to be intrinsically linked to the app (i.e., started and stopped with it, dependant on some server resources shared with the app, etc.), but never for cleanup tasks like this. My bet is it's possible, but most probably server-specific, so I'm not sure I'd want to do that as I hate being tied to any particular app server.

Another option I considered but never tried to implement that SHOULD work is to write custom classes that will be stored in session that extend Thread. Then you can have a member that tells how long it can live for, and just kill it in run() when it's time. I've never done this because the idea of spawning all those threads sounds obviously bad, but again it comes down to the usage pattern of the system I suspect... If you maybe have a ResultSet that you want to keep reusing if it exists, but you want it to always refresh after five minutes for instance, and you know your not going to have so many concurrent sessions that the number of threads wouldn't kill you, it might be a good way to go. I'm not sure what number of threads starts to be cause for concern, it has a lot to do obviously with server resources and expected system load, but this idea actually had quite a bit of appeal to me, it was just quicker to implement what I wound up doing (and time to market was the primary driver, as it usually is, and what the business wants and when tends to trump design work unfortunately).


From: Mike Duffy <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: Strategies for Clearing Session Objects
Date: Wed, 26 May 2004 19:04:52 -0700 (PDT)

System performance will obviously increase if unnecessary objects are cleared from the session.

I'd be interested in the strategies used by members of this list to clear unnecessary objects from
the session.


I think the most basic solution is not to clutter the session in the first place, but beyond that,
please share any specific strategies that you think are useful.


Thanks.

Mike




__________________________________ Do you Yahoo!? Friends. Fun. Try the all-new Yahoo! Messenger. http://messenger.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


_________________________________________________________________
Stop worrying about overloading your inbox - get MSN Hotmail Extra Storage! http://join.msn.click-url.com/go/onm00200362ave/direct/01/



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to