aspose file tools*
The moose likes Servlets and the fly likes After calling destroy method in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "After calling destroy method in servlet" Watch "After calling destroy method in servlet" New topic
Author

After calling destroy method in servlet

Madhu GM
Greenhorn

Joined: Mar 09, 2004
Posts: 11
Hi All,

I have written a servlet code and tried to call the servlet's destroy method. Now I can able to call the destroy method.
What happens after i call that method ?.. weather it will remove the servlet ?.. if not what it will do ?..

Thanks
Madhu
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The destroy method is intended to be called by the servlet container. It's not something you would want to call your self.

It's a place for you to put cleanup code, if necessary.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Madhu GM
Greenhorn

Joined: Mar 09, 2004
Posts: 11
I agree with you Ben ..

But want to know what happens when u call the the destroy methos rather than the container ..
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Just make a call to destroy yourself. Believe me nothing is gonna happen. And if you override the destroy method and inside that place something like,

System.out.println("hey i got a call");

then you will get it printed, but nothing else. As Ben said, "its a place for you to put a cleanup code, if necessary".

cheers.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Looks like it does nothing.
It's there for you to override and put your cleanup code in.

Quote from the Servlet Specs SRV.14.2.6.1

destroy()
public void destroy()
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed. After the servlet container calls this method, it will not call the service method again on this servlet. This method gives the servlet an opportunity to clean up any resources that are 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.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Adeel Ansari,
Our posts crossed....
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Ben Souther:
Adeel Ansari,
Our posts crossed....


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: After calling destroy method in servlet