net.i2p.router.tasks

## Class ShutdownHook

- java.lang.Object
- - java.lang.Thread
  - - net.i2p.router.tasks.ShutdownHook

- All Implemented Interfaces:
    Runnable

      public class ShutdownHook
      extends Thread

  Emergency shutdown hook for JVM termination. This hook is registered with the JVM Runtime to ensure clean router shutdown even if the normal shutdown process is bypassed or interrupted. It serves as a failsafe mechanism to handle unexpected JVM termination scenarios such as:
  - System.exit() calls outside normal shutdown flow
  - JVM crashes or fatal errors
  - Process termination signals (SIGTERM, etc.)
  - Power loss or system shutdown
  The hook logs the shutdown event and performs a hard shutdown to prevent the Java Service Wrapper from becoming confused about the router's state. Note: During normal router shutdown, this hook should be cancelled to avoid unnecessary emergency shutdown procedures.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.lang.Thread

      `Thread.State, Thread.UncaughtExceptionHandler`

  - ### Field Summary

    - ### Fields inherited from class java.lang.Thread

      `MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ShutdownHook(RouterContext ctx)` Create a new shutdown hook for emergency router shutdown.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `run()` Perform emergency shutdown when JVM is terminating.

    - ### Methods inherited from class java.lang.Thread

      `activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ShutdownHook

          public ShutdownHook(RouterContext ctx)

      Create a new shutdown hook for emergency router shutdown. This hook is registered with the JVM to ensure clean shutdown even if the normal shutdown process is bypassed.
      Parameters:
        `ctx` - router context for accessing router services

  - ### Method Detail

    - #### run

          public void run()

      Perform emergency shutdown when JVM is terminating. This method is called by the JVM during shutdown to ensure the router shuts down cleanly even in abnormal termination scenarios. It logs the shutdown and performs a hard shutdown. This is a failsafe mechanism - normal shutdown should cancel this hook to avoid unnecessary emergency procedures.
      Specified by:
        `run` in interface `Runnable`
      Overrides:
        `run` in class `Thread`