问题
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