Sun Java System Application Server Enterprise Edition 8.1 2005Q2 Developer's Guide

- Previous: Caching Servlet Results
- Next: Request Handling

### Instantiating and Removing Servlets

After the servlet engine instantiates the servlet, the servlet engine calls the servlet’s `init()` method to perform any necessary initialization. You can override this method to perform an initialization function for the servlet’s life, such as initializing a counter.

When a servlet is removed from service, the servlet engine calls the `destroy()` method in the servlet so that the servlet can perform any final tasks and deallocate resources. You can override this method to write log messages or clean up any lingering connections that won’t be caught in garbage collection.

- Previous: Caching Servlet Results
- Next: Request Handling

- © 2010, Oracle Corporation and/or its affiliates