When is destroy of servlets called?

The destroy() method is called by container before removing a servlet instance from service and gives servlet an opportunity to clean up any resources being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the servlet's current state in memory.

The destroy() and init() methods are called only once in a servlet's lifetime while the service() method may be called multiple times. The destory() will be called :

  • when the container shuts down or the application shuts down;
  • when the container decides that there is a shortage of memory;
  • when this servlet hasn't got a request in a long time.

After the servlet container calls this method, it will not call the service method again on this servlet.

Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend

Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |