Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Servlets and the fly likes How many objects can be in Session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How many objects can be in Session" Watch "How many objects can be in Session" New topic

How many objects can be in Session

Saith Govind

Joined: Jan 24, 2003
Posts: 13
Is there any limit to the number of objects I keep in Httpsession object. Does putting more number of objects affect the performance of the servlet?
Please help.
Thank you so much..
Pete Harris
Ranch Hand

Joined: Feb 05, 2003
Posts: 39
In a word, no. The HttpSession Attribute list is usually backed by a HashMap and so it can grow unconstrained.
As for performance, the speed of retrieval of objects is constant, but the problem you may run into is the memory usage of the server if you have many sessions.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
A servlet engine has the option of serializing sessions out to disk if it wants to due to memory getting tight. (Not all servlet engines implement this, I know JRun does.) Thats why all objects you put in a session should implement Serializable.
Naturally recovering a session from disk introduces a delay.
I agree. Here's the link:
subject: How many objects can be in Session
It's not a secret anymore!