It's not a secret anymore!
The moose likes Servlets and the fly likes destroy() method of servlet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "destroy() method of servlet. " Watch "destroy() method of servlet. " New topic

destroy() method of servlet.

Varun Monga

Joined: Dec 15, 2006
Posts: 2
What if I call the destroy() method of servlet in the init() method of servlet ?

SCJP <br />Software Engineer<br /> <br />< href=">My Blog</a>
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42958
Welcome to JavaRanch.

The question is moot, because servlet code never calls the destroy method (or the init method). The servlet container does that.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

for more see this article about Servlet Container Works.. by Budi Kurniawan

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

The code would run, but the Servlet wouldn't actually be taken out of service. The destroy method is a method like any other method, but its purpose has to do with the lifecycle of the Servlet, which is managed by the web container.

A developer should never call the init or destroy method of a Servlet. We just put pertinent code there, and allow the container to invoke it.

-Cameron McKenzie
I agree. Here's the link:
subject: destroy() method of servlet.
It's not a secret anymore!