Why is it considered a good practice to make session scoped objects Serializable?

好久不见. 提交于 2020-01-13 06:13:26

问题


I often hear people saying that session scoped objects should implement Serializable ? Why it is so ? What will be the result if one doesn't do this ? Why not make this a part of the servlet specification then ? I know Tomcat doesn't complain if we do not do this . What about other app servers like JBoss, WebSphere or Weblogic ?


回答1:


This allows the servlet container to either store the contents of a session on disk, or to transfer session contents over the network to another server.

Why does the container need to store session on the disk (passivation)? Perhaps when the memory is full. When the session is needed again, it retrieves it from the disk back into memory (activation).

http://www.javapractices.com/topic/TopicAction.do?Id=110




回答2:


It allows container to move the session objects over the network or store them on a disk. It will helpful when you cluster your application with different nodes of server running in different physical boxes.



来源:https://stackoverflow.com/questions/12262759/why-is-it-considered-a-good-practice-to-make-session-scoped-objects-serializable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!