wood burning stoves 2.0*
The moose likes Servlets and the fly likes how many times is destroy()called in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how many times is destroy()called in servlet" Watch "how many times is destroy()called in servlet" New topic
Author

how many times is destroy()called in servlet

Ayaz uddin
Greenhorn

Joined: Jan 22, 2012
Posts: 6
how many times is destroy() called in servlet?
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

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...


SCJP 6 [SCJP - Old is Gold]
Arun Giridharan
Ranch Hand

Joined: Sep 30, 2010
Posts: 290

Container calls only once , but you can call any number of time !
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Jan 10, 2002
Posts: 61224
    
  66

Arun Giridharan wrote:Container calls only once , but you can call any number of time !

Repeated for emphasis: don't do this! Ever. Ever.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

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

Joined: Sep 30, 2010
Posts: 290

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

Joined: Jan 10, 2002
Posts: 61224
    
  66

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

Joined: Jan 10, 2002
Posts: 61224
    
  66

Essentially, it can happen up to once per servlet instance.
Arun Giridharan
Ranch Hand

Joined: Sep 30, 2010
Posts: 290

Bear Bibeault wrote:Essentially, it can happen up to once per servlet instance.

that's true.
Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 166

Really a nice explanation. Thanks Tim and Bibeault.


No pain, No gain.
OCJP 1.6
 
Don't get me started about those stupid light bulbs.
 
subject: how many times is destroy()called in servlet