Why does HttpServlet in java implement serializable?

Possible duplicate:
Why does the HttpServlet implement Serializable?

This question suddenly arose a couple of days ago in an internal discussion, and we did not seem to find a suitable answer for this. Can someone point me in the right direction?

Questions:

1) Why is the HttpServlet in java implements serializable ? It seems I have not found a logical reason for this.

2). Trying to figure it out, I looked at the api doc and found something interesting

 public abstract class HttpServlet extends GenericServlet implements Serializable 

Now it’s interesting that GenericServlet also extends Serializable . Thus, both the parent and child classes implement serializable. Isn't that an anti-pattern?

+6
source share
2 answers

1) Why does httpservlet in java implement serializable? It seems to me to find any logical reason for this.

Support for clustering and serialization between virtual machines, passivation, etc.

+7
source

Another reason is because web containers like Tomcat cause some interceptions when closed. These bindings save the state of applications / servlets on hdd, so when the web container restarts, the application does not lose its state.

+1
source

Source: https://habr.com/ru/post/897134/


All Articles