Servlet Initialization and Destruction
At Agent startup, the Agent instantiates the servlet, and then calls the init() method on the servlet. Each time a client request arrives, the Agent calls a handler method on the servlet. Before the Agent shuts down, it calls the destroy() method on the servlet.
A servlet acquires resources through the init() method and releases resources in the destroy() method. The Agent always calls init() before forwarding requests to the servlet and always calls destroy() when the servlet is removed from service. However, because the servlet is instantiated at Agent startup, the Agent may construct the servlet before an incoming request invokes it. Further, the Agent may take the servlet out of service long before the servlet is destroyed. A servlet can take advantage of this situation by deferring resource acquisition until the Agent calls init() and releasing resources as soon as the Agent calls destroy().