HttpServlet Lifecycle and Serialization

I wonder if the init method of the HttpServlet is called after deserialization.

I don’t know when any container ever serializes a servlet, but it implements the Serializable interface, so there is an opportunity to do this.

The JavaDoc for the init method states: "Called by the servlet container to indicate to the servlet that the servlet is in maintenance."

Is deserialization equal to “commissioned”?

+6
source share
1 answer

So far I have never dealt with a container that would replace a servlet by serializing it, and I honestly cannot imagine when a modern container will do it, but I always understood that init() is called exactly once for a servlet in its life loop, so it will not be triggered again by deserialization. As with Serializable , you need to write special processing by doing readFields() .

+5
source

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


All Articles