Home > Servlet > What happens if you call destroy() from init() in java servlet?

What happens if you call destroy() from init() in java servlet?

destroy() gets executed and the initialization process continues.

In java servlet, destroy() is not supposed to be called by the programmer.

But, if it is invoked, it gets executed. Now the question is, will the servlet instance get destroyed? No, it will not.

destroy() method is not supposed to and will not destroy a java servlet. Don’t get confused by the name. It should have been better, if it was named onDestroy().

The meaning of destroy() in java servlet is, the content gets executed just before when the container decides to destroy the servlet.  But if you invoke the destroy() method yourself, the content just gets executed and then the respective process continues. With respective to this question, the destroy() gets executed and then the servlet initialization gets completed.

Categories: Servlet
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.