File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "maximum size of the session object" Watch "maximum size of the session object" New topic

maximum size of the session object

Madhu GM

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

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

Joined: Mar 22, 2000
Posts: 13037
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.

Paul Sturrock

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:
subject: maximum size of the session object
jQuery in Action, 3rd edition