It's not a secret anymore!*
The moose likes Servlets and the fly likes maximum size of the session object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "maximum size of the session object" Watch "maximum size of the session object" New topic
Author

maximum size of the session object

Madhu GM
Greenhorn

Joined: Mar 09, 2004
Posts: 11
Hi All,

Is there any restriction on the size of the session Object ?
If Yes, What is the maximum size of data that can be stored in Session Object.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Short answer: No.

A session is not really a placeholder. It doesn't have a size.
When you think of "putting an object in session" what you're really doing is binding an object (which lives on the heap) to the session with a reference.

The limits you will run into have more to do with the amount of RAM allocated to your appserver, the number of sessions running, and the size and number of the objects being kept in memory due to having an active reference around.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Session is implemented with a Java collection Map so it doesn't really store the objects - it stores a reference to an object. The only practical limit is the amount of memory you want to use. So if 100 sessions all have a reference to the same object, the only extra memory required is for the keys and references.
Servlet containers are allowed to manage sessions by serializing them to disk - particularly when memory gets tight - in that case all of the attached objects must be Serializable or you lose them.

Bill
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Also if you are planning to write any code which might put so much in session that you hit OutOfMemoryExceptions, I'd revist your design. Its better to keep sessions small; for example when you use things like clustering sessions need replicated between web container instances. Big sessions == a lot to replicate.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: maximum size of the session object
 
Similar Threads
size of object in setAttribute
max size of a string
Maximum size of Java Object
Heap Memory Analysis - Distribution among Session, Stateful EJB and other objects
Tomcat and Optimizeit throwing Out of memory error