You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Woodchuck <wo...@yahoo.com> on 2004/10/19 18:46:08 UTC

last available function call when web app stops or app server shuts down

hihi all,

which class/function do i need to extend/override so that i can
absolutely guarantee that code is executed before the web app is
killed?  ie. if someone stops Tomcat or stops my Struts web app
instance, and i want to execute some code before it really goes down.

is this easy/possible?

thanks in advance,
woodchuck


		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: last available function call when web app stops or app server shuts down

Posted by Matt Bathje <mp...@ntsource.com>.
Woodchuck wrote:
> hihi all,
> 
> which class/function do i need to extend/override so that i can
> absolutely guarantee that code is executed before the web app is
> killed?  ie. if someone stops Tomcat or stops my Struts web app
> instance, and i want to execute some code before it really goes down.
> 

The way I do it is to extend the o.a.s.action.ActionServlet class and 
set it up to be the main servlet in web.xml using something like:

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>com.mysite.ExtendedActionServlet</servlet-class>

<load-on-startup>1</load-on-startup>
</servlet>


And then override ActionServlet's destroy() method to take care of 
anything you need done when the site is shut down. Make sure you call 
super.destroy in it though :)



Matt

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: last available function call when web app stops or app server shuts down

Posted by Bill Siggelkow <bi...@bellsouth.net>.
http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html


Woodchuck wrote:

> hihi all,
> 
> which class/function do i need to extend/override so that i can
> absolutely guarantee that code is executed before the web app is
> killed?  ie. if someone stops Tomcat or stops my Struts web app
> instance, and i want to execute some code before it really goes down.
> 
> is this easy/possible?
> 
> thanks in advance,
> woodchuck
> 
> 
> 		
> _______________________________
> Do you Yahoo!?
> Declare Yourself - Register online to vote today!
> http://vote.yahoo.com


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: last available function call when web app stops or app server shuts down

Posted by Brian Showalter <bs...@sbcglobal.net>.
--- Woodchuck <wo...@yahoo.com> wrote:
> hihi all,
> 
> which class/function do i need to extend/override so that i can
> absolutely guarantee that code is executed before the web app is
> killed?  ie. if someone stops Tomcat or stops my Struts web app
> instance, and i want to execute some code before it really goes
> down.
> 
> is this easy/possible?

Certainly, just create a class that implements the
javax.servlet.ServletContextListener interface, and configure your
webapp's web.xml file as follows:

<listener>
   <listener-class>your.new.ListenerClass</listener-class>
</listener>

Put the code you want to execute before the webapp is shut down in
the contextDestroyed() method of your listener class.

You can configure several types of event listeners, including
listeners that fire when a session is created or destroyed, an object
is bound or unbound in a session, or an attribute is changed.  Refer
to the Servlet 2.3 or 2.4 spec for further details.

Brian


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org