It's not a secret anymore!
The moose likes Servlets and the fly likes HttpSession ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpSession ..." Watch "HttpSession ..." New topic

HttpSession ...

Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
hi all,
Could anyone clear my doubts regarding HttpSession..
1) Is storing the objects in session a good process with respect to memory management.i mean, does session objects take too much memeory ??
2) pardon me if this is a dumb question
i have String Str1 which has about 3000 charactes..
and another String Str2 which has only 3 characters
im putting Str1 in one session and Str2 in another session..
Does Str1 and Str2 (size of the data it holds) play any role in memory consumed by the session ???

SCJP, SCWCD, SCBCD, Oracle Certified Professional (SQL n PL/SQL)
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33113

1) It depends on what you put in the session. I have seen recommendations between 1K and 10K for optimal session size. You can write out a sample session to a file if you want to see how much memory it takes up (see ObjectOutputStream in the API.)
2) Yes, the bigger string will take up more memory. Everything you put in the session uses some memory. Even a field set to null will take up a byte.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
Thanks Jeanne
I agree. Here's the link:
subject: HttpSession ...
It's not a secret anymore!