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.

Results 1 to 3 of 3

Thread: Why is HttpServlet serialized

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Location
    gurgaon
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why is HttpServlet serialized

    Why is HttpServlet serializable? Do we need to serialize the controllers in our web-application? Pros of it?


  2. #2
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: Why is HttpServlet serialized

    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.

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Why is HttpServlet serialized

    Quote Originally Posted by payalBansal View Post
    Why is HttpServlet serializable?
    This answers: Why do GenericServlet and HttpServlet implement the Serializable interface?
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

Similar Threads

  1. Replies: 3
    Last Post: October 23rd, 2011, 01:27 PM
  2. httpServlet response
    By lorik in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 17th, 2011, 10:29 AM