aspose file tools*
The moose likes Servlets and the fly likes session variables. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "session variables." Watch "session variables." New topic
Author

session variables.

sawan parihar
Ranch Hand

Joined: Aug 24, 2004
Posts: 250
Hi All,
I am having some doubts about keeping the data in the session. Just want to get your inputs. My question is , when will be the performance of the j2ee application better if we keep the all the data in the session or we keep it in request scope.

Somehow i feel that if say in struts we keep the form bean in the session scope it will effect the response time and overall performance of the application as compared to if we keep form bean is request scope.

But i am not sure I am right or not. May be you guys can help me out in understanding this.

Thanks for your reply in advance.

Sawan


Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The more you load up your sessions, the more memory your app will require to run. This can greatly affect your scalability. If you're clustering sessions, adding more servers won't necessarily help.

On the other hand, if keeping commonly used objects in session can help to reduce object creation and destruction it may cut down both CPU usage and reduce the number of times garbage collection is run (expensive). Cutting down database calls by caching commonly used data in session can greatly improve the speed.

There are tradeoffs and there is no one, set rule for achieving the right balance. If you're expecting ten million users a day, keeping session data in memory for every user is not a good idea. For an intranet or low volume site where users log in and stay in for a long time, caching the right data instead of reading from disk every time can make your app scream.

Build your app for clarity, profile it to find the bottlnecks, and optimize where you can make the biggest improvments.
[ January 04, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

Build your app for clarity, profile it to find the bottlnecks, and optimize where you can make the biggest improvments


Engrave this on a plaque and hang it in every office.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alex Sharkoff
Ranch Hand

Joined: Apr 11, 2004
Posts: 209
Hi all,

I'd like to add that when thinking of storing an attribute in one of the scopes (i.e. request, session, context or page scopes) one needs to take into the count how long the attribute is to live.

Eg, when storing a bean in order to pass it JSP so that it can extract required values from this bean and create html, one would store such bean in a request because the web app does not need to know about this bean once it serviced the request (i.e. created an html and sent to the client).

On the other hand, when storing a bean that holds information collected over several pages (eg, shopping cart application), one could store such bean in a session.



Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Bear Bibeault:
Engrave this on a plaque and hang it in every office.

One couldn't ask for a better compliment than that. Thank you.
sawan parihar
Ranch Hand

Joined: Aug 24, 2004
Posts: 250
Hi all,
Thank you all very much. I got it.


Sawan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session variables.