Class ShutdownHook

  • All Implemented Interfaces:
    java.lang.Runnable

    public final class ShutdownHook
    extends java.lang.Thread
    This class provides a "shutdown" service to other classes. It sets up a single shutdown hook, which iterates through a series of objects that are registered with it, shutting them down in turn. This class currently supports java.io.Writer, java.io.OutputStream, and ObjectStoreWriterInterMineImpl. It allows objects to be wrapped in a WeakReference, so that the shutdown hook does not preclude those objects from being garbage collected. The objects are shut down in the opposite order to them being added to this ShutdownHook. Therefore, if you register objects to be shut down from the constructor, no object will be shut down before another object that relies on it for its own shutdown.
    Author:
    Matthew Wakeling
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static ShutdownHook getInstance()
      Get the instance of this ShutdownHook.
      static void registerObject​(java.lang.Object object)
      Registers an object with the shutdown hook.
      void run()  
      static void shutdown()
      Performs the shutdown.
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • getInstance

        public static ShutdownHook getInstance()
        Get the instance of this ShutdownHook.
        Returns:
        the ShutdownHook instance
      • registerObject

        public static void registerObject​(java.lang.Object object)
        Registers an object with the shutdown hook.
        Parameters:
        object - the object
      • shutdown

        public static void shutdown()
        Performs the shutdown.
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
        See Also:
        Thread.run()