> -----Original Message-----
> From: Christopher Schultz [mailto:[email protected]]
> Sent: Tuesday, February 07, 2012 3:09 PM
> To: Tomcat Users List
> Subject: Re: Shutdown Hooks not firing when tomcat is shutdown from
> within a webapp
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Andrew,
>
> On 2/7/12 2:40 PM, Andrew Kujtan wrote:
> > When I call System.exit() tomcat doesn't actually shutdown
>
> That's weird.
>
> > it looks like it just is deadlocking or something as I am getting
> > a timeout on the call that runs it.
>
> What does a thread dump show you?
>
Yikes, It is showing it is waiting on the Catalina shutdown hook. What is that
hook doing?
here is the relevant trace,
"Asynchronous Notification 'interface
com.evertz.registry.ServerRegistryListener: masterChanged'" daemon prio=6
tid=0x28c77000 nid=0x16d8 in Object.wait() [0x2899f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x08bc3ac0> (a
org.apache.catalina.startup.Catalina$CatalinaShutdownHook)
at java.lang.Thread.join(Thread.java:1143)
- locked <0x08bc3ac0> (a
org.apache.catalina.startup.Catalina$CatalinaShutdownHook)
at java.lang.Thread.join(Thread.java:1196)
at
java.lang.ApplicationShutdownHooks.runHooks(ApplicationShutdownHooks.java:79)
at
java.lang.ApplicationShutdownHooks$1.run(ApplicationShutdownHooks.java:24)
at java.lang.Shutdown.runHooks(Shutdown.java:79)
at java.lang.Shutdown.sequence(Shutdown.java:123)
at java.lang.Shutdown.exit(Shutdown.java:168)
- locked <0x23c8bf68> (a java.lang.Class for java.lang.Shutdown)
at java.lang.Runtime.exit(Runtime.java:90)
at java.lang.System.exit(System.java:904)
at
com.evertz.web.worker.ShutdownManager.shutDown(ShutdownManager.java:27)
at com.evertz.WebShutdownWrapper.stop(WebShutdownWrapper.java:40)
at com.evertz.WebShutdownWrapper.run(WebShutdownWrapper.java:30)
at com.evertz.util.boot.ShutdownAction.run(ShutdownAction.java:57)
at
com.evertz.redirect.ClientRedirectionManager.handleNewMaster(ClientRedirectionManager.java:71)
at
com.evertz.redirect.ClientRedirectionManager.masterChanged(ClientRedirectionManager.java:94)
at
com.evertz.redirect.ClientRedirectionManager.access$300(ClientRedirectionManager.java:20)
at
com.evertz.redirect.ClientRedirectionManager$MasterChangeMonitor.masterChanged(ClientRedirectionManager.java:136)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
com.evertz.prod.util.notifier.NotifierInvocationHandler.issueNotification(NotifierInvocationHandler.java:119)
at
com.evertz.prod.util.notifier.async.AsynchronousInvocationHandler.access$000(AsynchronousInvocationHandler.java:16)
at
com.evertz.prod.util.notifier.async.AsynchronousInvocationHandler$1.run(AsynchronousInvocationHandler.java:38)
at java.lang.Thread.run(Thread.java:619)
Locked ownable synchronizers:
- None
> > On the bright side System.exit() does trigger the shutdown hook to
> > be called, even though the server doesn't shut down, it just
> > becomes unresponsive but the process remains and is still bound to
> > all of its ports.
>
> Again, that seems weird. Do you have some kind of deadlock occurring
> in your shutdown code? It sounds like:
>
> System.exit: calls your shutdown hook, JVM does not stop
> Bootstrap.main({"stop"}): avoids your shutdown hook, JVM stops
>
> Maybe you should check your shutdown hook. :)
The shutdown hook is just a sysout now. And that runs successfully.
>
> > If I call both,
> >
> > org.apache.catalina.startup.Bootstrap.main(new String[] {
> > "stop"}); System.exit(0);
> >
> > Tomcat shuts down, and my hook gets called, but I don't know how
> > ridiculous I want to take this already hacky thing...
>
> It's a pretty ridiculous hack in any case, right?
Indeed :(
>
> > Probably stupid question, but is calling System.exit() from a
> > webapp supposed to be able to kill tomcat?
>
> Yes. It should kill the JVM, which should shut down everything. If you
> want to protect your JVM from webapps that might call System.exit(),
> then you need to run under a SecurityManager.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk8xhMEACgkQ9CaO5/Lv0PBXCgCgmM81JJasiDH1rD3lx5yHJTa6
> 8dsAnii8qNVXOpPbSVNJCfRGnZmPoyV/
> =Xsi4
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]