Why is HttpServlet serializable? Do we need to serialize the controllers in our web-application? Pros of it?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Why is HttpServlet serializable? Do we need to serialize the controllers in our web-application? Pros of it?
This question comes up every now and then, and you'll find a number of discussions on this if you search for "httpservlet serializable". It's good that you're asking this question though.
The general opinion is HttpServlet is marked Serializable to give the servlet container the option to "passivate" the servlet (remove from memory and write the servlet into the file system). It seems that this can be useful for some containers to passivate servlets before a restart. There are also suggestions that this allows the container to put servlets that are not in use into "hibernation" thereby freeing up memory, as well as to duplicate servlets instances to other containers in a clustered environment.
Personally I'm not sure how this can be useful when servlets should be thin (and so quick to be instantiated as needed, and do not take up much heap space). They should also be stateless (state information is stored in the Session object, not in the servlet) so that multiple instances of the same servlet in a cluster of servlet containers should function identically to each other, and so there's no need to duplicate servlet instances in the cluster.
Andrea, www.andbin.net — SCJP 5 (91%) – SCWCD 5 (94%)
Useful links for Java beginners – My new project Java Examples on Google Code