How many ways we can destroy the servlet in ur program

Showing Answers 1 - 22 of 22 Answers

Ravindra

  • Feb 4th, 2006
 

v can't destroy a servlet by our program.it is only done by the server and the server administration.when a server is shut down the servlet is destroyed.

  Was this answer useful?  Yes

Pradeep Jaladi

  • Feb 10th, 2006
 

hi Guys,We can destroy the servlet running in the server.if no sessions / users are active. suppose if a session is expired , or no longer any user is connected . By using httpsesion Listener check whether any session exist's or not. if not we do it by servlet destroy() method. we their is a request for the same servlet next time it will start from ground ( Servlet initlization etc...).

  Was this answer useful?  Yes

ashish negi

  • Feb 13th, 2006
 

we can create a temparory servlet which can destroy after every resuest fulfillment,i just forgeted the method to write it.there is no way to distroy the servlet.

  Was this answer useful?  Yes

Lavanya

  • Mar 16th, 2006
 

calling destroy() is not going to unload the servlet!!! It just executes the clean up actions written by the servlet developer in the destroy method.

  Was this answer useful?  Yes

Nagender

  • Apr 19th, 2006
 

I think only once we can destroy the servlet after service method is executed.

  Was this answer useful?  Yes

siva kumar reddy

  • Jul 31st, 2006
 

actuall says it is only way .but thereoticall says it is two ways  depends upon the webcontainer.

1)

in all the containers whenever we stop the webapplication the servlet will be destoryed.

2)

but  some containers do whenever changed .class file that time the webcontainer destroy the old servlet object and create a servlet object.

  Was this answer useful?  Yes

angelina

  • Apr 11th, 2007
 

The destroy() gets called 2 times

1. When web application (browser) running on the web container gets closed.
2. web container (server) is shut down

hirags

  • Jul 17th, 2007
 

Guys pls
refer these ... Please ensure your answer is not  mislead some body..

http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/Servlet.html
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.

http://www.jguru.com/faq/view.jsp?EID=1029043
destroy() is a servlet life-cycle method called by servlet container to kill the instance of the servlet.
The answer to your question is "Yes". You can call destroy() from within the service(). It will do whatever logic you have in destroy() (cleanup, remove attributes, etc.) but it won't "unload" the servlet instance itself.

You do not manage the life cycle of servlets in the program; the servlet engine does.

[Alex adds:]

On the other hand, if the question is,

"Is it possible that the servlet container will call destroy() while the servlet is still processing a request inside service() on a different thread?"

then the answer is also yes, but it's a degenerate case. The servlet container is required to wait a reasonable amount of time for current requests to finish processing. So if your request is not totally lagging, it should work out fine. If you're spending more than a few seconds processing a request, that's a UI problem that you should try to work out first.

Check the servlet spec for more details.

BTW, destroy() does not imply garbage collection. The instance may live on in memory long after destroy() is called.

mallikarjun

  • Jan 23rd, 2012
 

We can destroy servlet in two ways one is when the server time out and another one is when power off.

  Was this answer useful?  Yes

sujata waghmare

  • Jan 10th, 2014
 

i think..only one time ...only used to destroy()..

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions