public class PriorityHook extends Object
Hooklets are stored in a priority ordered map and executed by a single dedicated thread when the JVM terminates. All modifications are synchronised to make the class thread-safe.
Use unique priorities between 0-100 so that unrelated
components do not interfere with each other's shutdown ordering.
| Modifier and Type | Method and Description |
|---|---|
static boolean |
add(int priority,
Runnable hook)
Add a shutdown hook with a specified priority.
|
static <H extends Hooklet> |
addAndGet(H hooklet)
Add a custom shutdown hook.
|
static void |
clear()
Remove the registered JVM shutdown hook and discard all hooklets.
|
static PriorityHook |
getRegisteredHook()
Obtain the singleton managing the shutdown hook, if present.
|
void |
onShutdown()
Execute registered hooklets in priority order.
|
public static boolean add(int priority,
Runnable hook)
Will prevent adding the same hook (by parameter's class) more than once, return false in that case.
priority - value passed to Hooklet.priority()hook - action to run on shutdowntrue if the hook was newly registeredNullPointerException - if hook is nullpublic static <H extends Hooklet> H addAndGet(H hooklet)
Will prevent adding the same hook (by parameter's class) more than once, return the existing one in that case.
See Hooklet.identity().
H - hooklet subtypehooklet - instance to registerNullPointerException - if hooklet is nullpublic static void clear()
public void onShutdown()
public static PriorityHook getRegisteredHook()
PriorityHook instance or nullCopyright © 2026 Chronicle Software Ltd. All rights reserved.