*
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
Author

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
saiprasanna
sandy li
Greenhorn

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


<a href="http://www.sugoo.com" 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="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: when destroy method is called