- Type Parameters:
T
- result type
- All Implemented Interfaces:
UnsafeSupplier<T>
A utility task is timed, potentially blocking, and non-business critical. For example, establishing a database connection. Utility tasks are not required to complete before the JVM can exit.
To ensure threads are tied to the lowest level parent group possible, the utility executor should be initialized by the main bootstrap method or closest reasonable equivalent, i.e., ServletListener, as in the example below.
Class.forName(IuUtilityWorkloadController.class.getName());
Implementation Note: The executor backing this workload
controller is deliberately small and cannot be configured. Utility
tasks should typically complete in 5ms or less
under normal environment conditions, and only run into exhaustion issues when
downstream resources slow down. The small size of the utility executor allow
RejectedExecutionException
provide fail-fast behavior as preferable
to destabilizing the entire application.
-
Constructor Summary
ConstructorsConstructorDescriptionIuUtilityTaskController
(UnsafeSupplier<T> task, Instant expires) Creates a utility task controller. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
doBefore
(UnsafeRunnable task, Instant expires) Runs a utility task.get()
Gets a result using unsafe code.static <T> T
getBefore
(UnsafeSupplier<T> factory, Instant expires) Gets a value from a utility factory.
-
Constructor Details
-
IuUtilityTaskController
Creates a utility task controller.- Parameters:
task
-UnsafeSupplier
utility taskexpires
-Instant
the task will expire
-
-
Method Details
-
doBefore
public static void doBefore(UnsafeRunnable task, Instant expires) throws TimeoutException, Throwable Runs a utility task.- Parameters:
task
- utility taskexpires
-Instant
the task must be completed by- Throws:
TimeoutException
- atexpires
if the task has not completed normallyThrowable
- if thrown from the task
-
getBefore
public static <T> T getBefore(UnsafeSupplier<T> factory, Instant expires) throws TimeoutException, Throwable Gets a value from a utility factory.- Type Parameters:
T
- value type- Parameters:
factory
- utility factoryexpires
-Instant
the value must be supplied by- Returns:
- value
- Throws:
TimeoutException
- atexpires
if the value has not been suppliedThrowable
- if thrown from the factory
-
get
Description copied from interface:UnsafeSupplier
Gets a result using unsafe code.- Specified by:
get
in interfaceUnsafeSupplier<T>
- Returns:
- The result.
- Throws:
Throwable
- If thrown by the unsafe code.
-