This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes destroy method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "destroy method" Watch "destroy method" New topic

destroy method

Malhar Barai
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Hi all,
Instead of destroy being called by the container, can we explicity call the destroy method IN the service method.

Malhar Barai
SOA & Java Book
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
Well, strictly, it's just a method like any other, so yes, you can.
However, the container will call destroy when the servlet or JSP is unloaded, whether you have called it already or not, so you have to be careful that you make it safe to call twice if you plan to call it yourself.
What worries me though, is why you think it might be useful. Can you explain a little more what you want to do this for? It may be that we can suggest a better alternative.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Malhar Barai
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Actually I was thrown upon this question & was wondering what could be done. What I thought was that the destroy method would be over-ridden.
I agree. Here's the link:
subject: destroy method
Similar Threads
WA #1.....word association
how to test destroy() in a servlet
ServletException from destroy( )
when is destroy called
when destroy method will call