You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ho Fat Tsang <na...@gmail.com> on 2008/03/28 03:15:57 UTC

Shutdown Hook in Tomcat 5.5.26

Dear all tomcat expert,

   I am falling a scenario which my shutdown hook has not been executed when
the tomcat stop normally. I.e. through the SHUTDOWN script / SHUTDOWN
command / NT services shutdown. Tomcat looks everything when shutdown but
nothing related to shutdown hook has been called.

  The shutdown hook i implemented is just a dummy thread like below:

public class TestThread extend Thread
{
     public void run()
     {
           System.out.println("Invoking shutdown");
     }
}


  The hook is executed ONLY when i press CTRL+C using console but it is not
desired solution as my projects required it should run under service /
daemon mode.

Regards,
Twinsen.

Re: Shutdown Hook in Tomcat 5.5.26

Posted by Ho Fat Tsang <na...@gmail.com>.
Hello Chris,

      Thank for your reply and yes. It seems System.out is subtle at that
moment and it is not a good indicator for validation. I have re-written
something else and it works fine.

But let me elaborate what i want to achieve. I would like to deliver a alert
email when the JVM shutdown. The root cause why the shutdown hook does not
work because there is a hidden exception at the previous implementation
because the webapp class loader reject to load the class after tomcat has
been shutdown.

So i have to use a separate thread with appropriate context class loader to
execute my shutdown hook.

Thank
Twinsen.

On Fri, Mar 28, 2008 at 9:49 PM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Twinsen,
>
> Ho Fat Tsang wrote:
> | public class TestThread extend Thread
> | {
> |      public void run()
> |      {
> |            System.out.println("Invoking shutdown");
> |      }
> | }
> |
> |   The hook is executed ONLY when i press CTRL+C using console but it
> is not
> | desired solution as my projects required it should run under service /
> | daemon mode.
>
> Are you sure that System.out is going somewhere predictable when you run
> Tomcat as a service? Can you see other Tomcat shutdown information?
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.8 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkfs90wACgkQ9CaO5/Lv0PCoGQCeOdtgHF0h6ezUFfzTZj8qdKwW
> +l4AmwcJHvMIX9+waoWT42hlC0Gtmbk6
> =uBuo
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Shutdown Hook in Tomcat 5.5.26

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Twinsen,

Ho Fat Tsang wrote:
| public class TestThread extend Thread
| {
|      public void run()
|      {
|            System.out.println("Invoking shutdown");
|      }
| }
|
|   The hook is executed ONLY when i press CTRL+C using console but it
is not
| desired solution as my projects required it should run under service /
| daemon mode.

Are you sure that System.out is going somewhere predictable when you run
Tomcat as a service? Can you see other Tomcat shutdown information?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkfs90wACgkQ9CaO5/Lv0PCoGQCeOdtgHF0h6ezUFfzTZj8qdKwW
+l4AmwcJHvMIX9+waoWT42hlC0Gtmbk6
=uBuo
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org