It's not a secret anymore!
The moose likes Servlets and the fly likes when destroy method is called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "when destroy method is called" Watch "when destroy method is called" New topic

when destroy method is called

sai prasanna
Ranch Hand

Joined: May 02, 2005
Posts: 167
hi all,

destroy method is called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed. how container knows that all the threads are exited and where we specify the timeout period for a servlet.

thanks in advance
sandy li

Joined: May 08, 2006
Posts: 3
Thanks. I learn a lot from your words.

<a href="" target="_blank" rel="nofollow">Sugoo</a>
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
I do not know how other servlet containers do the job, so I'll give you overview how I implemented this in my servlet container.
1. All servlets create threads in certain thread group servlet container assigned them
2. Upon receiving termination signal, a servlet container sends an interrupt signal to all groups assigned for servlets
3. Servlet container enumerates all thread in groups and checks if they are still alive, if no alive go to 5
4. Servlet container is enumerating threads again after timeout time reached and destroys all still active threads
5. Servlet container calls destroy of all servlets
6. Servlet container exits

Tough in space?, <a href="" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="" target="_blank" rel="nofollow">Check it here.</a><br /><a href="" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
I agree. Here's the link:
subject: when destroy method is called
It's not a secret anymore!