Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
The
destroy
method provided by theHttpServlet
class destroys the servlet and logs the destruction. To destroy any resources specific to your servlet, override thedestroy
method. Thedestroy
method should undo any initialization work and synchronize persistent state with the current in-memory state.The following example shows the
destroy
method that accompanies the pseudo-codeinit
method in the previous lesson:public class DBServlet ... { Connection connection = null; ... // the init method public void destroy() { // Close the connection and allow it to be garbage collected connection.close(); connection = null; } }A server calls the
destroy
method after all service calls have been completed, or a server-specific number of seconds have passed, whichever comes first. If your servlet handles any long-running operations,service
methods might still be running when the server calls thedestroy
method. You are responsible for making sure those threads complete. The next lesson shows you how.The
destroy
method shown above expects all client interactions to be completed when thedestroy
method is called, because the servlet has no long-running operations.
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2002 Sun Microsystems, Inc. All rights reserved.