mainly because i was trying to write a single class for both the tomcat and standalone versions, and also to avoid making the business logic dependent on a web environment. (ie to provide fail-safeness within the business logic, rather than it being an external service that needs to be checked)
Elie > Hi There, > > Why not use the ServletContextListener interface to do all of your cleanup > stuff when the contextDestroyed method is called ? > > Pete > > -----Original Message----- > From: Elie Medeiros [mailto:[EMAIL PROTECTED] > Sent: 03 March 2004 10:44 > To: [EMAIL PROTECTED] > Subject: addShutdownHook in Tomcat does not seem to get called on > shutdown > > > > Hi, > > I added a shutdown hook in my app, which works fine when I run it in > standalone mode, but which does not seem to get called when Tomcat stops. > > The shutdown hook operates according to following the following semantics: > __________________________________________________________________________ > class MyApp{ > > public void doSomething(){ > ShutdownHook sdh = new ShutdownHook(); > synchronized(Runtime.getRuntime()){ > Runtime.getRuntime().addShutdownHook(sdh); > } > // > //do something here > // > logger.info("Finished doing something"); > //remove shutdown hook once process has finished > sdh.setFinished(); > if (!sdh.isInitialised()){ > synchronized(Runtime.getRuntime()){ > Runtime.getRuntime().removeShutdownHook(sdh); > } > } > } > > private class ShutdownHook extends Thread { > private boolean INITIALISED = false; > private boolean FINISHED = false; > > public void run() { > this.INITIALISED = true; > this.setPriority(2); > logger.debug("Shutdown hook: shutdown thread started - a > shutdown has > been requested"); > out : > while (true) { > //keep on looping until the claaing app has finished > synchronized(this.FINISHED){ > if (this.FINISHED == true) { > logger.debug("Shutdown hook: parent > program finished, allowing > shutdown process to complete"); > return; > } > } > } > } > > public synchronized boolean isInitialised() { > return this.INITIALISED; > } > > public synchronized void setFinished() { > this.FINISHED = true; > } > } > } > __________________________________________________________________________ > > > The log does not show any trace of the shutdown hook being called, and > the process does indeed not complete before Tomcat shuts down, which to > me sounds like the hook is not getting registered properly for some > reason. Any ideas why this might be happening? I am running Tomcat > 4.1.18 on Windows 2K (no advice about switching to Linux please). > > Thanks, > > Elie > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]