- All Implemented Interfaces:
Runnable
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(int)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 Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandlerField Summary
FieldsModifier and TypeFieldDescriptionprivate static final AtomicIntegerCounts the hooks created.private final RouterContextThe router being shut down.private final intThis hook's number, used in its name.Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITYConstructor Summary
ConstructorsConstructorDescriptionCreate a new shutdown hook for emergency router shutdown.Method Summary
All MethodsMethods inherited from class Thread
activeCount, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, threadId, toString, yield
Field Details
_context
The router being shut down.__id
Counts the hooks created._id
private final int _idThis hook's number, used in its name.
Constructor Details
ShutdownHook
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 Details
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.