• Post Reply Bookmark Topic Watch Topic
  • New Topic

why objects stored in session should be serializable?

 
Rajiv KumarRai
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Why is it that objects stored in session object should be serializable?

Thanks,
Rajiv
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A J2EE application can make use of multiple JVMs in order to improve application reliability and performance. In order to make the multiple JVMs appear as a single application to the end user, the J2EE container can replicate an HttpSession object across multiple JVMs so that if one JVM becomes unavailable another can step in and take its place without disrupting the flow of the application. This is only possible if all session data is serializable, allowing the session to be duplicated between the JVMs.
So, Sessions can be temporarily stored on disk or migrated to another application server. In order to make sure that objects in the session can be handled in those situations they need to be serailizable.

 
Rajiv KumarRai
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Abhay for the well explained answer..
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that even in a single JVM system, the servlet container may serialize a session to disk any time it wants to, for memory management purposes for example.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!