• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Putting object in session

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a question concerning performance.
Is there a problem if I put 10 object in the session? This approach will create some problem in the long run, it will make my application run slower.

Thank you for any comment.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As with most performance questions, the answer is "that depends".
Putting 10 objects into a single session is unlikely to impact performance. When you have 1000 simultaneous sessions, suddenly you have 10,000 objects hanging around and that can have a significant impact.
Of course, if you don't preserve that information in the session and you need it for each step a user performs, you will end up recreating it with each page and that can have a significant impact as well.
There are trade offs to be made with keeping the information local or fetching it when one needs it. You will have to do some testing to figure out what's best for your program.
Start here: EnterprisePerformance FAQ
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it would also depend on how big or small each of the objects are. But that alone would not justify keeping the objects in the session since you will have to check the size each time to add an attribute to any one of the objects.
Like Joe mentioned, It would also depend on the number of sessions being created and the number of servers/ JVMs handling the sessions.

HTH
Shikhar
 
Liviu Mitrofan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thank you for your ideas. But I have also another question.
Is it possible to creat an object as static field in another class instead of putting it in the session? What I mean is the fact that: is this object common for the entire application or per request?
Because I need an object in an action but one for every user and session. I don't want to interfere between session and users.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As explained in the Java Tutorial:

Fields that have the static modifier in their declaration are called static fields or class variables. They are associated with the class, rather than with any object. Every instance of the class shares a class variable, which is in one fixed location in memory

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joe
 
Oh, sure, you could do that. Or you could eat some pie. While reading this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic