Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why do GenericServlet and HttpServlet implement the Serializable interface?

0
Posted

Why do GenericServlet and HttpServlet implement the Serializable interface?

0

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.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.