File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Session Scope & Memory issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Session Scope & Memory issue" Watch "Session Scope & Memory issue" New topic

Session Scope & Memory issue

Vinod Kumar
Ranch Hand

Joined: Jan 18, 2002
Posts: 75

In one of the application, the development team used the ActionForm scope as "session". Form beans have list of objects (some cases hash map) which are been retrieved from DB.The issue is we started seeing out of memory errors and we feel the session scope for action form is causing problems.

As this app is in production, is there a way to fix this scope issue.? If struts config is changed to request scope...many UIs are failing as they have some dependency...
I know it is an open question....any one dealt with fixing this type of issue in a large scale app ( more than 400 UI)?

Thanks in advance.

Vinod Kumar
David Newton

Joined: Sep 29, 2008
Posts: 12617

What does "400 UI" mean?

In any case, I only keep things in session when I need them in session: I've never put things like search results etc. into a form bean, because they're not part of the form. I put those things in request scope so they'll be collected as soon as possible. If the items in session are data for things like drop-downs, etc. make sure they actually need to be in session scope (as opposed to application scope). If they were put in session for performance reasons consider doing the caching in a different layer.
Patrick Kok
Ranch Hand

Joined: Nov 12, 2009
Posts: 42
This is a good question.
We have the similar scenarios when we find a lot of layouts which have no interaction with struts actions.
These are mostly the jsp or a template made by sitemesh.
Since we cannot use url to past request object with href link (same with redirectAction), we must use session.
These sessions are spring sessin beans.
One solution that we do is to use struts2 dispatcher with sitemesh, such that the current layout (menu, navigation button highlight etc.) will be kept but the user can make change to the main body only.
For some pages (eg. item list table, search table etc.) that we must display the content BEFORE it gets submit action, then we must use session.

I am looking for a good solution to get rid of session.

Aditya Keyal
Ranch Hand

Joined: Dec 01, 2008
Posts: 71
Another solution would be to probably remove the form from the session everytime an expected flow is completed.

For ex. in a registration flow if you have

Reg. Page A -> Reg. Page B -> Reg Summary -> Reg. Confirm

You can remove the form bean from the session before going into the Reg. Confirm and set in the request any data you want in the Reg. Confirm page. The only problem in this approach will be that if the user moves away from the expected path i.e. he does not reach the Reg. Confirm page then the memory remains loaded with the data. But this approach should ideally improve the overall memory management for you with minimum efforts.

- Aditya Webservices Blog
I agree. Here's the link:
subject: Session Scope & Memory issue
It's not a secret anymore!