top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Why do GenericServlet and HttpServlet implement the Serializable interface?

+1 vote
380 views
Why do GenericServlet and HttpServlet implement the Serializable interface?
posted Nov 4, 2015 by Joy Nelson

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

GenericServlet and HttpServlet implement the Serializable interface so that servlet engines can "hybernate" the servlet state when the servlet is not in use and reinstance it when needed or to duplicate servlet instances for better load balancing. I don't know if or how current servlet engines do this, and it could have serious implications, like breaking references to objects gotten in the init() method without the programmer knowing it. Programmers should be aware of this pitfall and implement servlets which are stateless as possible, delegating data store to Session objects or to the ServletContext. In general stateless servlets are better because they scale much better and are cleaner code.

answer Nov 5, 2015 by Karthick.c
...