What will happen when we call the destroy method in the init method? will the servlet exist?

Showing Answers 1 - 6 of 6 Answers

The destroy method is not called as it is considered unsuccessful initialization. During initialization, the servlet instance can throw an UnavailableException or a ServletException. In this case, the servlet must not be placed into active service and must be released by the servlet container.

  Was this answer useful?  Yes

prabhaker

  • Apr 6th, 2006
 

If it destroys the servlet,then where is LifeCycle of servelt,

it won,t destroy,it will destroy on or before shutting down ,or cosequtive requests are not coming.

Container will call it as a simple method call,that destroy method in Init method won't be considered as a lifecycle destroy method.

  Was this answer useful?  Yes

hsharma12

  • Apr 10th, 2006
 

I think destroy method cant be called up by user as its called by the container when there is no incoming request for the servlet or when the server is shutting down. So calling destroy method wont have any effect on the initialization of servlet.

Please correct me if something is wrong above. I will be thankful for the same.

  Was this answer useful?  Yes

HAMED KHAN

  • Apr 11th, 2006
 

We cannot call the destroy() explicitly because it is a lifecyle method. Not only destroy(), we cannot call any lifecyle method explicitly like init(), service() or destroy().

Now, No need of getting confused this is the correct answer, which you can verify it from java.sun.com website.

  Was this answer useful?  Yes

Manivannan Palanichamy

  • Aug 5th, 2006
 

The container calls the destroy() method of a servlet just before it is destroyed.

The reverse is not true.

I mean, if you manually call the destroy() method, the container doesnt kill the servlet -- simply the body of the destroy() method is executed just like a normal java method, and and the control returns to the caller.

(This is case same as calling the run() method of a Thread! a new thread is not created when you call run() method manually! -- Remember? :)  )

  Was this answer useful?  Yes

puneet

  • Aug 11th, 2006
 

Hi,

The servlet specifications clearly states that we can not explicity destroy the servlet instance by coding what so ever in destroy method.

We can only perform clean up operations.

So, if we call the service method in init, it will be called and Say I have Stop there then print it on console.

Instance can be unloded only when container calls destroy method.

Thanks,

Puneet

  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