public abstract class Hooklet extends Object implements Comparable<Hooklet>
PriorityHook.
Implementations should be effectively immutable. Registration may occur from many threads but each hooklet is executed sequentially by the shutdown thread.
Allocate unique priorities in the range 0-100. Smaller
values execute first and should be used for higher-level components.
| Constructor and Description |
|---|
Hooklet() |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(@NotNull Hooklet other)
Orders hooklets by priority then identity.
|
boolean |
equals(Object obj) |
int |
hashCode() |
protected Object |
identity()
Hooks are only called once but may be registered multiple times.
|
static Hooklet |
of(int priority,
Runnable hook)
Accepts callback and priority to produce shutdown hook object.
|
abstract void |
onShutdown()
Callback invoked by the shutdown thread.
|
abstract int |
priority()
Hooks with lesser priority will be called before hooks with greater priority.
|
String |
toString() |
public abstract void onShutdown()
public abstract int priority()
It is advised to allocate an unique priority in the range of 0-100. In general, more high level code needs to do its shutdown routines before lower level code. An example priority layout is given below:
0: Run before all hooks. For test/example use. 1-49: Release of network resources and stopping distributed activity. 50-89: Release of local resources and stopping data structures. 90-99 Cleanup of file system resources such as temporary directories. 100: Run after all hooks. For test/example use.
protected Object identity()
The default implementation returns this instance's class and should usually be sufficient.
public static Hooklet of(int priority, Runnable hook)
Hook callback class is used to check for identity, see identity().
priority - value returned by priority()hook - action to run on shutdownNullPointerException - if hook is nullpublic int compareTo(@NotNull
@NotNull Hooklet other)
compareTo in interface Comparable<Hooklet>other - hooklet to compareotherCopyright © 2026 Chronicle Software Ltd. All rights reserved.