8

What is the maximum limit (i.e. size) of data that a HTTPSession variable can hold? What will happen if this exceeds? And most importantly, what is the alternative approach to have the data throughout the session if the size exceeds the maximum size that a HTTPSession variable can hold?

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
user182944
  • 7,897
  • 33
  • 108
  • 174
  • if you decide to do this and ever come in situation you need to scale your application to more than one server you might have huge problems with load balancing, since traveling of sessions among servers will impose serious overhead... – ante.sabo Sep 07 '12 at 13:55

2 Answers2

9

There is no limit, other than the memory of your server. The alternatives are

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
0

There is a good recomendation to use data session on HttpSession with caution, mainly because many points must be considered and not only involved with data size.

  • HttpSession might be hijack if the connection is not secure. So, if a connection is not by a HTTPS, the chance to be hijacked is higher by comparasion with a HTTP.
  • The number of users estimated to use the service on the web. You can allocate all memory that is possible in the world, but if the solution is pre-allocating a session without any size limit, then the probability to have a OutOfMemory in the JVM when many users are using is high. For instance: a session data with 8 Kbytes multiplied by 100.000 users can reach 800 MBytes.
  • The session timeout configured in the server, a Websphere Application Server is set to 30 minutes by default. If the session timeout is decreased, it might help the JVM overload, on the other hand you can let the users very anger.
  • If the solution uses many servers (clusters), one thing to think is about the Sharing Http Sessions between them.

Furthemore information, I recomend you to read Chapter 2 - Http Sessions in the book Performance Analysis for Java Web Sites by Ken Hygh, Ruth Willenborg, and Stacy Joines

Thiago Ferreira
  • 165
  • 2
  • 5