Struts and session cleanup
Struts puts a locale attribute in the session, but that should remain for the duration of the user's session. It's not something you should worry about cleaning up. The container will take care of it when the session times-out. If you put an ActionForm in the session (not really recommended anymore, unless you are using a wizard), then you can choose to remove it when you are done. The ActionMapping is provided to the Action, and you can look to see what scope the form is in. If you are done with the data, and the form is in session scope, then you can just remove it. If you do a lot of this, add a utility function to your base Action, so you can just call something like removeSessionForm(request); as needed. If you are throwing other things into the session yourself, many people put them all in a map or some other wrapper, to make it easy to see what your application has put into the session. But for the most part, the session does take care of itself, and the container will clean it up when it times out. Struts really isn't involved. HTH, Ted. -- Ted Husted, Struts in Action http://husted.com/struts/book.html - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Struts and session cleanup
Hi, Can any one suggest what is the best practise for session clean up ? In my opinion, Struts makes session clean up a mess. I understand that I can use scope for session data. But, for global sessions, what is the good way to clean sessions ? Thanks, _ Catch the Oscar fever. See winners losers. http://server1.msn.co.in/MSNSpecials/oscar2003/index.asp Right here - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Struts and session cleanup
I'm not sure what you mean by global sessions you mean application scoped items? Also using scope for session data doesn't garbage clean it when its done. Do you mean to scope it in a different scope? -Tim -Original Message- From: varanasi kiran [mailto:[EMAIL PROTECTED] Sent: Thursday, April 03, 2003 1:24 PM To: [EMAIL PROTECTED] Subject: Struts and session cleanup Hi, Can any one suggest what is the best practise for session clean up ? In my opinion, Struts makes session clean up a mess. I understand that I can use scope for session data. But, for global sessions, what is the good way to clean sessions ? Thanks, _ Catch the Oscar fever. See winners losers. http://server1.msn.co.in/MSNSpecials/oscar2003/index.asp Right here - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Session Cleanup
Thanks, David. Putting commonly used collection in the application scope is a nice idea; both for storage space and performance reasons. Now how do I store my form beans in request instead of session? Is it the scope attribute of the action mapping that determines it? And what are performance implications of this change? Regards, ATTA - Original Message - From: David Graham [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 11:50 AM Subject: Re: Session Cleanup I believe struts leaves form beans in the session forever. They won't really grow in size though because they get reset on each use. You could also store them in the request if you're really worried about it. If I store collections in the session, I'll often remove them at the end of a transaction. So, when the user saves a form I remove the collection. In general, I try to keep common collections in the ServletContext. David From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: struts users mailing list [EMAIL PROTECTED] Subject: Session Cleanup Date: Thu, 17 Oct 2002 10:20:24 -0700 When does struts framework remove ActionFrom objects from the session, if at all. I'm worried if I'd be making my session object too large. Moreover, what are the best practices for storing html:select collections in the session? How and when to remove these collections from the session? Regards, ATTA _ Surf the Web without missing calls! Get MSN Broadband. http://resourcecenter.msn.com/access/plans/freeactivation.asp -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
RE: Session Cleanup
I often stored my form beans in a session scope. I've a routine that looping through the session and destroy the unused forms. The tricky part is how to determine with forms are no longer in used. Anyone out there using this technique? -Original Message- From: Craig R. McClanahan [mailto:craigmcc;apache.org] Sent: Thursday, October 17, 2002 3:37 PM To: Struts Users Mailing List Subject: Re: Session Cleanup On Thu, 17 Oct 2002, atta ur-rehman wrote: Date: Thu, 17 Oct 2002 13:36:41 -0700 From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Thanks, David. Putting commonly used collection in the application scope is a nice idea; both for storage space and performance reasons. Now how do I store my form beans in request instead of session? Is it the scope attribute of the action mapping that determines it? Yes. And what are performance implications of this change? The set of attributes in the request or session object supplied by the servlet container is usually a HashMap, so performance of storing the form bean in either is equivalent. However, your app will benefit from the fact that the form bean is automatically released at the end of the request, so the overall memory occupancy of your app will likely be lower, but the CPU time consumption might be higher (due to increased garbage collection). For most apps, this tradeoff is very much worth it because having excess CPU capacity is more common than having excess memory to store the form beans in session scope in between requests. Regards, ATTA Craig -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org _ Introducing the all new and improved continental.com. With a totally new personalized design, it's the best place to go. Before you go. Continental Airlines. Work Hard. Fly Right. http://www.continental.com
RE: Session Cleanup
Hai wrote: I often stored my form beans in a session scope. I've a routine that looping through the session and destroy the unused forms. The tricky part is how to determine with forms are no longer in used. Anyone out there using this technique? I'm storing ActionForm instances in session scope because I do some bouncing around between resolution screens (user types a name, gets a list of matches, picks one, goes back to main form) and I don't want to put all that junk in hidden fields on the resolution screen so that it will be in the Request when I come back to the main form. This means that I'm not using the reset method-- the form gets initialized with what's read from the database, and then it sits in session scope getting manipulated by EditContactAction and ProcessContactAction until the user is happy. (No checkboxes, so there's nothing to reset.) I'm not quite there yet, but once I write the record to the DB, I will manually remove the form from the session. Then atta asked: Now is there a way to store collections in the request scope instead of session scope? by collections I mean, collections used to populate html:select controls? You can set request attributes: public void setAttribute(java.lang.String name, java.lang.Object o) Stores an attribute in this request. Attributes are reset between requests. -- Wendy Smoak Applications Systems Analyst, Sr. Arizona State University PA Information Resources Management
Re: Session Cleanup
Well, in the ServletRequest interface there are 2 methods getAttribute and setAttribute (you'll find identical methods in HttpSession and ServletContext). This is how you put objects into various scopes. So, in one of your Actions you would say: request.setAttribute(someName, myCollection); The jsp you forward to can get the myCollection object by saying: in JSTL: ${requestScope.someName} in jsp expression %= request.getAttribute(someName) % Does that help? Dave From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Date: Thu, 17 Oct 2002 14:43:48 -0700 Ok, David, I read the doc! now what? - Original Message - From: David Graham [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:58 PM Subject: Re: Session Cleanup Try looking through the servlet javadoc here: http://java.sun.com/j2ee/sdk_1.3/techdocs/api/ Look at HttpServletRequest and HttpSession David From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Date: Thu, 17 Oct 2002 13:55:55 -0700 Thanks Craig. That explains. I think we can afford few more cpu cycles instead of memory. Now is there a way to store collections in the request scope instead of session scope? by collections I mean, collections used to populate html:select controls? ATTA - Original Message - From: Craig R. McClanahan [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:36 PM Subject: Re: Session Cleanup On Thu, 17 Oct 2002, atta ur-rehman wrote: Date: Thu, 17 Oct 2002 13:36:41 -0700 From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Thanks, David. Putting commonly used collection in the application scope is a nice idea; both for storage space and performance reasons. Now how do I store my form beans in request instead of session? Is it the scope attribute of the action mapping that determines it? Yes. And what are performance implications of this change? The set of attributes in the request or session object supplied by the servlet container is usually a HashMap, so performance of storing the form bean in either is equivalent. However, your app will benefit from the fact that the form bean is automatically released at the end of the request, so the overall memory occupancy of your app will likely be lower, but the CPU time consumption might be higher (due to increased garbage collection). For most apps, this tradeoff is very much worth it because having excess CPU capacity is more common than having excess memory to store the form beans in session scope in between requests. Regards, ATTA Craig -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org _ Surf the Web without missing calls! Get MSN Broadband. http://resourcecenter.msn.com/access/plans/freeactivation.asp -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org _ Surf the Web without missing calls! Get MSN Broadband. http://resourcecenter.msn.com/access/plans/freeactivation.asp -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: Session Cleanup
So how do you know which ones are not used anymore? - Original Message - From: Hoang, Hai [EMAIL PROTECTED] To: 'Struts Users Mailing List' [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:49 PM Subject: RE: Session Cleanup I often stored my form beans in a session scope. I've a routine that looping through the session and destroy the unused forms. The tricky part is how to determine with forms are no longer in used. Anyone out there using this technique? -Original Message- From: Craig R. McClanahan [mailto:craigmcc;apache.org] Sent: Thursday, October 17, 2002 3:37 PM To: Struts Users Mailing List Subject: Re: Session Cleanup On Thu, 17 Oct 2002, atta ur-rehman wrote: Date: Thu, 17 Oct 2002 13:36:41 -0700 From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Thanks, David. Putting commonly used collection in the application scope is a nice idea; both for storage space and performance reasons. Now how do I store my form beans in request instead of session? Is it the scope attribute of the action mapping that determines it? Yes. And what are performance implications of this change? The set of attributes in the request or session object supplied by the servlet container is usually a HashMap, so performance of storing the form bean in either is equivalent. However, your app will benefit from the fact that the form bean is automatically released at the end of the request, so the overall memory occupancy of your app will likely be lower, but the CPU time consumption might be higher (due to increased garbage collection). For most apps, this tradeoff is very much worth it because having excess CPU capacity is more common than having excess memory to store the form beans in session scope in between requests. Regards, ATTA Craig -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org _ Introducing the all new and improved continental.com. With a totally new personalized design, it's the best place to go. Before you go. Continental Airlines. Work Hard. Fly Right. http://www.continental.com -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: Session Cleanup
Try looking through the servlet javadoc here: http://java.sun.com/j2ee/sdk_1.3/techdocs/api/ Look at HttpServletRequest and HttpSession David From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Date: Thu, 17 Oct 2002 13:55:55 -0700 Thanks Craig. That explains. I think we can afford few more cpu cycles instead of memory. Now is there a way to store collections in the request scope instead of session scope? by collections I mean, collections used to populate html:select controls? ATTA - Original Message - From: Craig R. McClanahan [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:36 PM Subject: Re: Session Cleanup On Thu, 17 Oct 2002, atta ur-rehman wrote: Date: Thu, 17 Oct 2002 13:36:41 -0700 From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Thanks, David. Putting commonly used collection in the application scope is a nice idea; both for storage space and performance reasons. Now how do I store my form beans in request instead of session? Is it the scope attribute of the action mapping that determines it? Yes. And what are performance implications of this change? The set of attributes in the request or session object supplied by the servlet container is usually a HashMap, so performance of storing the form bean in either is equivalent. However, your app will benefit from the fact that the form bean is automatically released at the end of the request, so the overall memory occupancy of your app will likely be lower, but the CPU time consumption might be higher (due to increased garbage collection). For most apps, this tradeoff is very much worth it because having excess CPU capacity is more common than having excess memory to store the form beans in session scope in between requests. Regards, ATTA Craig -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org _ Surf the Web without missing calls! Get MSN Broadband. http://resourcecenter.msn.com/access/plans/freeactivation.asp -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: Session Cleanup
Thanks Craig. That explains. I think we can afford few more cpu cycles instead of memory. Now is there a way to store collections in the request scope instead of session scope? by collections I mean, collections used to populate html:select controls? ATTA - Original Message - From: Craig R. McClanahan [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:36 PM Subject: Re: Session Cleanup On Thu, 17 Oct 2002, atta ur-rehman wrote: Date: Thu, 17 Oct 2002 13:36:41 -0700 From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Thanks, David. Putting commonly used collection in the application scope is a nice idea; both for storage space and performance reasons. Now how do I store my form beans in request instead of session? Is it the scope attribute of the action mapping that determines it? Yes. And what are performance implications of this change? The set of attributes in the request or session object supplied by the servlet container is usually a HashMap, so performance of storing the form bean in either is equivalent. However, your app will benefit from the fact that the form bean is automatically released at the end of the request, so the overall memory occupancy of your app will likely be lower, but the CPU time consumption might be higher (due to increased garbage collection). For most apps, this tradeoff is very much worth it because having excess CPU capacity is more common than having excess memory to store the form beans in session scope in between requests. Regards, ATTA Craig -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: Session Cleanup
On Thu, 17 Oct 2002, atta ur-rehman wrote: Date: Thu, 17 Oct 2002 13:36:41 -0700 From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Thanks, David. Putting commonly used collection in the application scope is a nice idea; both for storage space and performance reasons. Now how do I store my form beans in request instead of session? Is it the scope attribute of the action mapping that determines it? Yes. And what are performance implications of this change? The set of attributes in the request or session object supplied by the servlet container is usually a HashMap, so performance of storing the form bean in either is equivalent. However, your app will benefit from the fact that the form bean is automatically released at the end of the request, so the overall memory occupancy of your app will likely be lower, but the CPU time consumption might be higher (due to increased garbage collection). For most apps, this tradeoff is very much worth it because having excess CPU capacity is more common than having excess memory to store the form beans in session scope in between requests. Regards, ATTA Craig -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: Session Cleanup
I believe struts leaves form beans in the session forever. They won't really grow in size though because they get reset on each use. You could also store them in the request if you're really worried about it. If I store collections in the session, I'll often remove them at the end of a transaction. So, when the user saves a form I remove the collection. In general, I try to keep common collections in the ServletContext. David From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: struts users mailing list [EMAIL PROTECTED] Subject: Session Cleanup Date: Thu, 17 Oct 2002 10:20:24 -0700 When does struts framework remove ActionFrom objects from the session, if at all. I'm worried if I'd be making my session object too large. Moreover, what are the best practices for storing html:select collections in the session? How and when to remove these collections from the session? Regards, ATTA _ Surf the Web without missing calls! Get MSN Broadband. http://resourcecenter.msn.com/access/plans/freeactivation.asp -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: Session Cleanup
Thanks David, that certainly help. And excuse me for my naivety! Thanks once more. Regards, ATTA - Original Message - From: David Graham [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 5:44 PM Subject: Re: Session Cleanup Well, in the ServletRequest interface there are 2 methods getAttribute and setAttribute (you'll find identical methods in HttpSession and ServletContext). This is how you put objects into various scopes. So, in one of your Actions you would say: request.setAttribute(someName, myCollection); The jsp you forward to can get the myCollection object by saying: in JSTL: ${requestScope.someName} in jsp expression %= request.getAttribute(someName) % Does that help? Dave From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Date: Thu, 17 Oct 2002 14:43:48 -0700 Ok, David, I read the doc! now what? - Original Message - From: David Graham [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:58 PM Subject: Re: Session Cleanup Try looking through the servlet javadoc here: http://java.sun.com/j2ee/sdk_1.3/techdocs/api/ Look at HttpServletRequest and HttpSession David From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Date: Thu, 17 Oct 2002 13:55:55 -0700 Thanks Craig. That explains. I think we can afford few more cpu cycles instead of memory. Now is there a way to store collections in the request scope instead of session scope? by collections I mean, collections used to populate html:select controls? ATTA - Original Message - From: Craig R. McClanahan [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:36 PM Subject: Re: Session Cleanup On Thu, 17 Oct 2002, atta ur-rehman wrote: Date: Thu, 17 Oct 2002 13:36:41 -0700 From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Thanks, David. Putting commonly used collection in the application scope is a nice idea; both for storage space and performance reasons. Now how do I store my form beans in request instead of session? Is it the scope attribute of the action mapping that determines it? Yes. And what are performance implications of this change? The set of attributes in the request or session object supplied by the servlet container is usually a HashMap, so performance of storing the form bean in either is equivalent. However, your app will benefit from the fact that the form bean is automatically released at the end of the request, so the overall memory occupancy of your app will likely be lower, but the CPU time consumption might be higher (due to increased garbage collection). For most apps, this tradeoff is very much worth it because having excess CPU capacity is more common than having excess memory to store the form beans in session scope in between requests. Regards, ATTA Craig -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org _ Surf the Web without missing calls! Get MSN Broadband. http://resourcecenter.msn.com/access/plans/freeactivation.asp -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org _ Surf the Web without missing calls! Get MSN Broadband. http://resourcecenter.msn.com/access/plans/freeactivation.asp -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: Session Cleanup
After doing a quick check through the source ... find . -name *.java | xargs grep removeAttribute It would appear there are a few places that the method gets called. A cursory examination of each suggests they are all to remove things which were temporarily placed there and shouldn't be left. In other words, I don't believe Struts ever removes you form bean. atta ur-rehman wrote: When does struts framework remove ActionFrom objects from the session, if at all. I'm worried if I'd be making my session object too large. Moreover, what are the best practices for storing html:select collections in the session? How and when to remove these collections from the session? Regards, ATTA -- Eddie Bush -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: Session Cleanup
Ok, David, I read the doc! now what? - Original Message - From: David Graham [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:58 PM Subject: Re: Session Cleanup Try looking through the servlet javadoc here: http://java.sun.com/j2ee/sdk_1.3/techdocs/api/ Look at HttpServletRequest and HttpSession David From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Date: Thu, 17 Oct 2002 13:55:55 -0700 Thanks Craig. That explains. I think we can afford few more cpu cycles instead of memory. Now is there a way to store collections in the request scope instead of session scope? by collections I mean, collections used to populate html:select controls? ATTA - Original Message - From: Craig R. McClanahan [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:36 PM Subject: Re: Session Cleanup On Thu, 17 Oct 2002, atta ur-rehman wrote: Date: Thu, 17 Oct 2002 13:36:41 -0700 From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Thanks, David. Putting commonly used collection in the application scope is a nice idea; both for storage space and performance reasons. Now how do I store my form beans in request instead of session? Is it the scope attribute of the action mapping that determines it? Yes. And what are performance implications of this change? The set of attributes in the request or session object supplied by the servlet container is usually a HashMap, so performance of storing the form bean in either is equivalent. However, your app will benefit from the fact that the form bean is automatically released at the end of the request, so the overall memory occupancy of your app will likely be lower, but the CPU time consumption might be higher (due to increased garbage collection). For most apps, this tradeoff is very much worth it because having excess CPU capacity is more common than having excess memory to store the form beans in session scope in between requests. Regards, ATTA Craig -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org _ Surf the Web without missing calls! Get MSN Broadband. http://resourcecenter.msn.com/access/plans/freeactivation.asp -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: Session Cleanup
No problem, it's a good habit to get into checking the javadoc or user guides before posting a question to a list or forum. Not that we don't want to help; it just allows you to ask good questions. Good luck! David From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Date: Thu, 17 Oct 2002 18:10:31 -0700 Thanks David, that certainly help. And excuse me for my naivety! Thanks once more. Regards, ATTA - Original Message - From: David Graham [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 5:44 PM Subject: Re: Session Cleanup Well, in the ServletRequest interface there are 2 methods getAttribute and setAttribute (you'll find identical methods in HttpSession and ServletContext). This is how you put objects into various scopes. So, in one of your Actions you would say: request.setAttribute(someName, myCollection); The jsp you forward to can get the myCollection object by saying: in JSTL: ${requestScope.someName} in jsp expression %= request.getAttribute(someName) % Does that help? Dave From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Date: Thu, 17 Oct 2002 14:43:48 -0700 Ok, David, I read the doc! now what? - Original Message - From: David Graham [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:58 PM Subject: Re: Session Cleanup Try looking through the servlet javadoc here: http://java.sun.com/j2ee/sdk_1.3/techdocs/api/ Look at HttpServletRequest and HttpSession David From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Date: Thu, 17 Oct 2002 13:55:55 -0700 Thanks Craig. That explains. I think we can afford few more cpu cycles instead of memory. Now is there a way to store collections in the request scope instead of session scope? by collections I mean, collections used to populate html:select controls? ATTA - Original Message - From: Craig R. McClanahan [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:36 PM Subject: Re: Session Cleanup On Thu, 17 Oct 2002, atta ur-rehman wrote: Date: Thu, 17 Oct 2002 13:36:41 -0700 From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Thanks, David. Putting commonly used collection in the application scope is a nice idea; both for storage space and performance reasons. Now how do I store my form beans in request instead of session? Is it the scope attribute of the action mapping that determines it? Yes. And what are performance implications of this change? The set of attributes in the request or session object supplied by the servlet container is usually a HashMap, so performance of storing the form bean in either is equivalent. However, your app will benefit from the fact that the form bean is automatically released at the end of the request, so the overall memory occupancy of your app will likely be lower, but the CPU time consumption might be higher (due to increased garbage collection). For most apps, this tradeoff is very much worth it because having excess CPU capacity is more common than having excess memory to store the form beans in session scope in between requests. Regards, ATTA Craig -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org _ Surf the Web without missing calls! Get MSN Broadband. http://resourcecenter.msn.com/access/plans/freeactivation.asp -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org _ Surf the Web without missing calls! Get MSN
RE: Session Cleanup
I have an admin main menu screen...in it I've a bunch of links to all of the admin tasks such as user profile, security, create category, etc... Once a user coming back to this main menu, I am assume they are finished working on a particular task. From here, I used the strut-config.xml and looping through and get the name of the form beans and removed it from the session object. If the user not finish working on it yet, then the framework created it again...no harm done. -Original Message- From: atta ur-rehman [mailto:attaurrehman;kapsconsulting.com] Sent: Thursday, October 17, 2002 4:13 PM To: Struts Users Mailing List Subject: Re: Session Cleanup So how do you know which ones are not used anymore? - Original Message - From: Hoang, Hai [EMAIL PROTECTED] To: 'Struts Users Mailing List' [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:49 PM Subject: RE: Session Cleanup I often stored my form beans in a session scope. I've a routine that looping through the session and destroy the unused forms. The tricky part is how to determine with forms are no longer in used. Anyone out there using this technique? -Original Message- From: Craig R. McClanahan [mailto:craigmcc;apache.org] Sent: Thursday, October 17, 2002 3:37 PM To: Struts Users Mailing List Subject: Re: Session Cleanup On Thu, 17 Oct 2002, atta ur-rehman wrote: Date: Thu, 17 Oct 2002 13:36:41 -0700 From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Thanks, David. Putting commonly used collection in the application scope is a nice idea; both for storage space and performance reasons. Now how do I store my form beans in request instead of session? Is it the scope attribute of the action mapping that determines it? Yes. And what are performance implications of this change? The set of attributes in the request or session object supplied by the servlet container is usually a HashMap, so performance of storing the form bean in either is equivalent. However, your app will benefit from the fact that the form bean is automatically released at the end of the request, so the overall memory occupancy of your app will likely be lower, but the CPU time consumption might be higher (due to increased garbage collection). For most apps, this tradeoff is very much worth it because having excess CPU capacity is more common than having excess memory to store the form beans in session scope in between requests. Regards, ATTA Craig -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org _ Introducing the all new and improved continental.com. With a totally new personalized design, it's the best place to go. Before you go. Continental Airlines. Work Hard. Fly Right. http://www.continental.com -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Session Cleanup
When does struts framework remove ActionFrom objects from the session, if at all. I'm worried if I'd be making my session object too large. Moreover, what are the best practices for storing html:select collections in the session? How and when to remove these collections from the session? Regards, ATTA
Re: Session Cleanup
as a final addendum - the struts-config file allows you to determine what scope your form beans sit in action type=my.action name=my.bean scope=request etc etc chanoch - Original Message - From: David Graham [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, October 18, 2002 2:36 AM Subject: Re: Session Cleanup No problem, it's a good habit to get into checking the javadoc or user guides before posting a question to a list or forum. Not that we don't want to help; it just allows you to ask good questions. Good luck! David From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Date: Thu, 17 Oct 2002 18:10:31 -0700 Thanks David, that certainly help. And excuse me for my naivety! Thanks once more. Regards, ATTA - Original Message - From: David Graham [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 5:44 PM Subject: Re: Session Cleanup Well, in the ServletRequest interface there are 2 methods getAttribute and setAttribute (you'll find identical methods in HttpSession and ServletContext). This is how you put objects into various scopes. So, in one of your Actions you would say: request.setAttribute(someName, myCollection); The jsp you forward to can get the myCollection object by saying: in JSTL: ${requestScope.someName} in jsp expression %= request.getAttribute(someName) % Does that help? Dave From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Date: Thu, 17 Oct 2002 14:43:48 -0700 Ok, David, I read the doc! now what? - Original Message - From: David Graham [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:58 PM Subject: Re: Session Cleanup Try looking through the servlet javadoc here: http://java.sun.com/j2ee/sdk_1.3/techdocs/api/ Look at HttpServletRequest and HttpSession David From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Date: Thu, 17 Oct 2002 13:55:55 -0700 Thanks Craig. That explains. I think we can afford few more cpu cycles instead of memory. Now is there a way to store collections in the request scope instead of session scope? by collections I mean, collections used to populate html:select controls? ATTA - Original Message - From: Craig R. McClanahan [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:36 PM Subject: Re: Session Cleanup On Thu, 17 Oct 2002, atta ur-rehman wrote: Date: Thu, 17 Oct 2002 13:36:41 -0700 From: atta ur-rehman [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: Session Cleanup Thanks, David. Putting commonly used collection in the application scope is a nice idea; both for storage space and performance reasons. Now how do I store my form beans in request instead of session? Is it the scope attribute of the action mapping that determines it? Yes. And what are performance implications of this change? The set of attributes in the request or session object supplied by the servlet container is usually a HashMap, so performance of storing the form bean in either is equivalent. However, your app will benefit from the fact that the form bean is automatically released at the end of the request, so the overall memory occupancy of your app will likely be lower, but the CPU time consumption might be higher (due to increased garbage collection). For most apps, this tradeoff is very much worth it because having excess CPU capacity is more common than having excess memory to store the form beans in session scope in between requests. Regards, ATTA Craig -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org