• Post Reply Bookmark Topic Watch Topic
  • New Topic

call detroy in init

 
sitaram irrinki
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we call destroy() in init("...") and
service(".....") methods?if it is possible what type
of servlets is it
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but think about what you are asking. Can you think of any valid reason to explicitly call a servlet's destroy() method as part of its initialization or in response to a request?
 
Debashish Chakrabarty
Ranch Hand
Posts: 231
Firefox Browser Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can guess that this was another tricky interview question!

Now, as Paul said, one must think why we would want to do that. The init(), destroy() etc are the life-cycle methods, callback methods for the servlet container to invoke as and when the situation warrants in the Servlet's life-cycle. But they are afterall methods, like any other Java methods, sp you may very well invoke them directly. Question is, why would you like to do it using methods meant for the container to invoke, why not write a custom method and call them at "an appropriate time". This appropriate time would be known to you only if you are able to understand the life-cyle of the Servlet well, and probably this was what the interviewer was testing you on.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!