| Author |
Session Management--Telling objects to go away!
|
Russell Ray
Ranch Hand
Joined: Apr 25, 2005
Posts: 116
|
|
Would someone be so kind to point in the right direction on how to manage a web session? I have a web application and the memory footprint continues to grow as users kill their browsers. I have been told WAS is hanging onto objects to long. The best way to handle this quickly is manage the session programmatically and destroy the objects when the session is "terminated" by killing the browser. Thank you for taking the time to read my post! Russ
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
When the session expires, the objects will be released and free for Garbage Collection (GC). There is no reliable way to know when a browser has been closed. You might want to shorten the length of your sessions.
I have been told WAS is hanging onto objects to long.
You've been told by whom? And, what is "too" long?
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
|
|
Also note that you can remove individual references when they are no longer needed with the HttpSession method "removeAttribute" - depending on your architecture you may be able to reduce the memory footprint that way. Bill
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
The best way to handle this quickly is manage the session programmatically and destroy the objects when the session is "terminated" by killing the browser.
True. Assuming you can accurately communicate to the server when a browser window is closed, which unfortunately you can't, and assuming the user will actually close the browser when they are finished, which they may not. The usual way to handle this is to time inactive sessions out. Search this forum if you don't know how to do that. (Dang! Too slow) [ June 17, 2005: Message edited by: Paul Sturrock ]
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
DC Dalton
Ranch Hand
Joined: May 28, 2001
Posts: 287
|
|
Ahh yes the old "stupid users wont use the logout function on my site" problem... man I know it all too well. I would have to ask a few questions.. what kind of goodies are you storing in the users sessions? (hopefully not the magna carta) are you setting the interval for time out with setMaxInactiveInterval? (if so for how long) there is a semi decent way to remind them or force them to log out.. I actually just found it a while back but its not 100% (may help though) in Javascript there is a function called onbeforeunload... you place it in your body tag just like the onload .... now here's where it gets kind of tricky. You have to check to make sure they are closing the page or going to a site OTHER than your and if they are you can throw a confirm at them. If they click the OK on the confirm you can use a location.href to send them thru a logout servlet.. if not you set the onbeforeunload to null and they get no confirm. It a pai but I have used it in an online appplication and it worked pretty good. the part that sucks about it is if they have javascript disabled, then it wont work. You may want to look into that and HOW MUCH info you are storing in the sessions. If you are sucking up tons of memory I have a feeling you may be stuffing too much into them.. Hope this helps
|
 |
 |
|
|
subject: Session Management--Telling objects to go away!
|
|
|