Class ShutdownHook

java.lang.Object
java.lang.Thread
clazzfish.core.util.ShutdownHook
All Implemented Interfaces:
Shutdownable, Runnable
Direct Known Subclasses:
AbstractMonitor, ClasspathAgent, ClazzStatistic

public class ShutdownHook extends Thread implements Shutdownable
This class has the necessary methods for registration a class as shutdown hook. For this you must overwrite the Thread.run() method which is called during shutdown.
Since:
3.0
Author:
oboehm
  • Constructor Details

    • ShutdownHook

      public ShutdownHook()
  • Method Details

    • isShutdownHook

      public boolean isShutdownHook()
      Here you can ask if the class was already registered as shutdown hook.
      Specified by:
      isShutdownHook in interface Shutdownable
      Returns:
      true if it is registered as shutdown hook.
    • addMeAsShutdownHook

      public void addMeAsShutdownHook()
      To be able to register the class as shutdown hook via JMX we can't use a static method - this is the reason why this additional method was added.

      NOTE: Don't add a class as shutdown hook in a web environment, e.g. Tomcat or other servlet container. It may avoid Tomcat from shuttong down as expected.

      Specified by:
      addMeAsShutdownHook in interface Shutdownable
    • removeMeAsShutdownHook

      public void removeMeAsShutdownHook()
      If you want to unregister the instance as shutdown hook you can use this (not static) method.
      Specified by:
      removeMeAsShutdownHook in interface Shutdownable