5 Replies Latest reply on Jan 26, 2010 6:43 AM by danydyn

    Shutdown hook issue

    danydyn

      Hi,

      I am running a spring based application in Jboss web container.

      I use the system property -Djboss.shutdown.forceHalt=false.

      I registered a jvm shutdown hook in one of my bean's init method using Runtime.addShutdownHook.

      This shutdown hook runs indeed when I stop the server, but I found out that if I halt the hook's execution, like

      by putting a breakpoint in it, eventually the jvm terminates, although I defined the system property above. (JVM should wait for all shutdown hooks to complete).

       

      Any explanation for this paranormal behaviour?

       

      Thanks

       

      Daniel.

        • 1. Re: Shutdown hook issue
          f_marchioni

          Interesting approach to solve the problem. Have you checked if it's an issue related with the IDE you're using ?

          As an alternative, you might consider registering an MBean:

           

          public class StartupService extends

                                  ServiceMBeanSupport implements StartupServiceMBean {

                            

              public StartupService() { }            

              . . . .

           

              @Override

              protected void stopService() throws Exception {

                    log.info("[StartupService ] Stopping Startup Mbean");

              }

          }

           

          stopService should kick in when the shutdown of the server is in progress.....

          hope it helps,

          Francesco

          MyJBossSite

          • 2. Re: Shutdown hook issue
            danydyn

            Thank you for answering,

            I use MyEclipse, it just calls org.Jboss.Shutdown with --shutdown argument.

            I'll give the JMX approach a try, but still, I'm puzzled...

            • 3. Re: Shutdown hook issue
              danydyn

              I loaded the server from command line with run.bat, stopped it with ctrl-c in the console,

              and guess what... it did not halt.

              Which means that probably the problem lyes with myeclipse.

               

              Thank you Fransesco for pointing it up for me.

               

              Daniel

              • 4. Re: Shutdown hook issue
                f_marchioni

                glad it helped.

                By the way, I had a peaceful morning so I had time to write a small article on my blog about it :

                http://www.mastertheboss.com/en/jboss-server/237-intercepting-jboss-shutdown.html

                regards

                Francesco

                • 5. Re: Shutdown hook issue
                  danydyn
                  I would also suggest the context listener approach - implement ServletContextListener and override contextDestroyed method.