Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how many times is destroy()called in servlet

 
Ayaz uddin
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how many times is destroy() called in servlet?
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
destroy() method is called :
1.) when on the whole, web application is undeployed from Servlet Container...
2.) When particular Servlet detail is deleted from web.xml...
 
Arun Giridharan
Ranch Hand
Posts: 290
Debian Fedora Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Container calls only once , but you can call any number of time !
 
Tim Moores
Bartender
Pie
Posts: 2496
10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun Giridharan wrote:Container calls only once ...

That's generally true, but the container is free to take a servlet out of service and put it back into service at any time it chooses. So you can't rely on it only happening once.

...but you can call any number of time !

That's true, but app code should never call the lifecycle methods (like init and destroy); that's for the container to do.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun Giridharan wrote:Container calls only once , but you can call any number of time !

Repeated for emphasis: don't do this! Ever. Ever.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ram Narayan.M wrote:2.) When particular Servlet detail is deleted from web.xml...

It has nothing at all to do with web.xml.
 
Arun Giridharan
Ranch Hand
Posts: 290
Debian Fedora Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:
Arun Giridharan wrote:Container calls only once ...

That's generally true, but the container is free to take a servlet out of service and put it back into service at any time it chooses. So you can't rely on it only happening once.

Can you explain on this , quite misleading.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun Giridharan wrote:
Tim Moores wrote:
Arun Giridharan wrote:Container calls only once ...

That's generally true, but the container is free to take a servlet out of service and put it back into service at any time it chooses. So you can't rely on it only happening once.

Can you explain on this , quite misleading.

It is not misleading at all. It is, in fact, quite accurate.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Essentially, it can happen up to once per servlet instance.
 
Arun Giridharan
Ranch Hand
Posts: 290
Debian Fedora Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Essentially, it can happen up to once per servlet instance.

that's true.
 
Kumaravadivel Subramani
Ranch Hand
Posts: 171
Java Linux Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really a nice explanation. Thanks Tim and Bibeault.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic