Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpServlet lifecycle and serialization

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

I don't know if any container ever serializes a servlet but it implements the Serializable interface so there is a possibility to do that.

The JavaDoc for the init method points out: "Called by the servlet container to indicate to a servlet that the servlet is being placed into service."

Is a deserialization equals "placed into service" ?

like image 213
cpater Avatar asked Jan 12 '12 15:01

cpater


1 Answers

While I have never actually dealt with a container that would swap out a servlet by serializing it, and I honestly can't really imagine when a modern container would do this, but I have always understood that init() is called exactly once for the servlet in its lifecycle, so, it would not be called again on deserialization. As with anything Serializable you would need to write special handling by implementing readFields().

like image 139
Sean Owen Avatar answered Dec 03 '22 13:12

Sean Owen