• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

call detroy in init

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can we call destroy() in init("...") and
service(".....") methods?if it is possible what type
of servlets is it
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 250
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic