Package com.mastfrog.giulius
Interface ShutdownHooks
- All Known Implementing Classes:
ShutdownHookRegistry
Deprecated.
use com.mastfrog.shutdown.hooks.ShutdownHooks directly - the
code has been moved there, and this class simply delegates to it.
A registry of shutdown hooks which run in LIFO order on shutdown; for cases
where the order cannot be determined by instantiaton/addition order, first,
last and middle (default) batches of hooks are provided.
Hooks are guaranteed to be run regardless of any other hook aborting or throwing an exception.
Hooks may be added such that they are weakly referenced, and will be omitted if garbage-collected.
Additions during shutdown are guaranteed to be run.
Executor services will have termination waited for for a settable timeout; the timeout is collective and is how long all executors will be waited for in aggregate. The default is three minutes.
- Author:
- Tim Boudreau
-
Method Summary
Modifier and TypeMethodDescriptionvoidadd(AutoCloseable toClose) Deprecated.Add an AutoCloseable to be cancelled to the default batch; the AutoCloseable will be weakly referenced.voidDeprecated.Add a Runnable to the default batch.Deprecated.add(ExecutorService toShutdown) Deprecated.Add an executor service to the default batch; the executor service will be strongly referenced; when hooks are run, all executors are first shut down, and then in a separate pass, awaited for termination en-banc up to the expiration of a timeout.voidDeprecated.Add a timer to be cancelled to the default batch; the timer will be weakly referenced.addFirst(AutoCloseable toClose) Deprecated.Add an AutoCloseable to be cancelled to the batch which runs first; the AutoCloseable will be weakly referenced.Deprecated.Add a Runnable to the batch which runs first.Deprecated.addFirst(ExecutorService toShutdown) Deprecated.Add an executor service to the batch which runs first; the executor service will be strongly referenced; when hooks are run, all executors are first shut down, and then in a separate pass, awaited for termination en-banc up to the expiration of a timeout.Deprecated.Add a timer to be cancelled to the batch which runs first; the timer will be weakly referenced.addFirstThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun) Deprecated.addFirstWeak(Runnable toRun) Deprecated.Add a Runnable to the batch which runs first, without keeping it strongly referenced.addFirstWeak(Callable<?> toRun) Deprecated.default ShutdownHooksaddFirstWeakThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun) Deprecated.addLast(AutoCloseable toClose) Deprecated.Add an AutoCloseable to be cancelled to the batch which runs last; the AutoCloseable will be weakly referenced.Deprecated.Add a Runnable to the batch which runs last.Deprecated.addLast(ExecutorService toShutdown) Deprecated.Add an executor service to the batch which runs last; the executor service will be strongly referenced; when hooks are run, all executors are first shut down, and then in a separate pass, awaited for termination en-banc up to the expiration of a timeout.Deprecated.Add a timer to be cancelled to the batch which runs last; the timer will be weakly referenced.addLastThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun) Deprecated.addLastWeak(Runnable toRun) Deprecated.Add a Runnable to the batch which runs first, without keeping it strongly referenced.addLastWeak(Callable<?> toRun) Deprecated.default ShutdownHooksaddLastWeakThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun) Deprecated.addThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun) Deprecated.Deprecated.Add a Runnable to the default batch, without keeping it strongly referenced.Deprecated.default ShutdownHooksaddWeakThrowing(com.mastfrog.function.throwing.ThrowingRunnable toRun) Deprecated.booleanDeprecated.Returns true if shutdown hooks are currently being run.intshutdown()Deprecated.Imperatively run shutdown tasks, clearing the set of tasks and deregistering the ShutdownHooks as a VM shutdown hook if it has been registered.
-
Method Details
-
isRunningShutdownHooks
boolean isRunningShutdownHooks()Deprecated.Returns true if shutdown hooks are currently being run.- Returns:
- True if hooks are running
-
add
Deprecated.Add a Runnable to the default batch.- Parameters:
toRun- A runnable
-
addLast
Deprecated.Add a Runnable to the batch which runs last.- Parameters:
toRun- A runnable- Returns:
- this
-
addFirst
Deprecated.Add a Runnable to the batch which runs first.- Parameters:
toRun- A runnable- Returns:
- this
-
addWeak
Deprecated.Add a Runnable to the default batch, without keeping it strongly referenced.- Parameters:
toRun- A runnable
-
addFirstWeak
Deprecated.Add a Runnable to the batch which runs first, without keeping it strongly referenced.- Parameters:
toRun- A runnable
-
addLastWeak
Deprecated.Add a Runnable to the batch which runs first, without keeping it strongly referenced.- Parameters:
toRun- A runnable
-
add
Deprecated.Add an executor service to the default batch; the executor service will be strongly referenced; when hooks are run, all executors are first shut down, and then in a separate pass, awaited for termination en-banc up to the expiration of a timeout.- Parameters:
toShutdown- An ExecutorService- Returns:
- this
-
addFirst
Deprecated.Add an executor service to the batch which runs first; the executor service will be strongly referenced; when hooks are run, all executors are first shut down, and then in a separate pass, awaited for termination en-banc up to the expiration of a timeout.- Parameters:
toShutdown- An ExecutorService- Returns:
- this
-
addLast
Deprecated.Add an executor service to the batch which runs last; the executor service will be strongly referenced; when hooks are run, all executors are first shut down, and then in a separate pass, awaited for termination en-banc up to the expiration of a timeout.- Parameters:
toShutdown- An ExecutorService- Returns:
- this
-
add
Deprecated.Add a timer to be cancelled to the default batch; the timer will be weakly referenced.- Parameters:
toCancel- A timer
-
addFirst
Deprecated.Add a timer to be cancelled to the batch which runs first; the timer will be weakly referenced.- Parameters:
toCancel- A timer- Returns:
- this
-
addLast
Deprecated.Add a timer to be cancelled to the batch which runs last; the timer will be weakly referenced.- Parameters:
toCancel- A timer- Returns:
- this
-
add
Deprecated.Add an AutoCloseable to be cancelled to the default batch; the AutoCloseable will be weakly referenced.- Parameters:
toClose- A resource to be closed
-
addFirst
Deprecated.Add an AutoCloseable to be cancelled to the batch which runs first; the AutoCloseable will be weakly referenced.- Parameters:
toClose- A resource to be closed- Returns:
- this
-
addLast
Deprecated.Add an AutoCloseable to be cancelled to the batch which runs last; the AutoCloseable will be weakly referenced.- Parameters:
toClose- A resource to be closed- Returns:
- this
-
add
Deprecated. -
addFirst
Deprecated. -
addLast
Deprecated. -
addFirstWeak
Deprecated. -
addLastWeak
Deprecated. -
addWeak
Deprecated. -
addThrowing
Deprecated. -
addFirstThrowing
Deprecated. -
addLastThrowing
Deprecated. -
addWeakThrowing
Deprecated. -
addFirstWeakThrowing
Deprecated. -
addLastWeakThrowing
Deprecated. -
shutdown
int shutdown()Deprecated.Imperatively run shutdown tasks, clearing the set of tasks and deregistering the ShutdownHooks as a VM shutdown hook if it has been registered.In general this should only be called by test frameworks and a few rare cases of applications that cleanly shut down all their state and reload themselves, or things run inside an isolating classloader whose shutdown tasks must run before the classloader is closed.
- Returns:
- The count of tasks run during shutdown
-