Hi, You're probably removing the shutdown hook too early. Why are you removing it at all?
Yoav Shapira Millennium ChemInformatics >-----Original Message----- >From: Elie Medeiros [mailto:[EMAIL PROTECTED] >Sent: Wednesday, March 03, 2004 5:44 AM >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] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]