-
public final class BackgroundTaskServiceProvides a service for submitting lengthy tasks to run on background threads.
A TaskType must be submitted with each task, which routes it to the appropriate executor. Setting the correct TaskType is critical as it can be used to enforce thread confinement. It also avoids short-running operations being held up by long-running operations submitted to the same executor.
-
-
Constructor Summary
Constructors Constructor Description BackgroundTaskService(ExecutorService errorExecutor, ExecutorService sessionExecutor, ExecutorService ioExecutor, ExecutorService internalReportExecutor, ExecutorService defaultExecutor)
-
Method Summary
Modifier and Type Method Description final Future<?>submitTask(TaskType taskType, Runnable runnable)Submits a task for execution on a single-threaded executor. final <T extends Any> Future<T>submitTask(TaskType taskType, Callable<T> callable)final Unitexecute(TaskType taskType, Runnable task)final Unitshutdown()Notifies the background service that the process is about to terminate. final <R extends Any> RunnableProvider<R>provider(TaskType taskType, Function0<R> provider)-
-
Constructor Detail
-
BackgroundTaskService
BackgroundTaskService(ExecutorService errorExecutor, ExecutorService sessionExecutor, ExecutorService ioExecutor, ExecutorService internalReportExecutor, ExecutorService defaultExecutor)
-
-
Method Detail
-
submitTask
final Future<?> submitTask(TaskType taskType, Runnable runnable)
Submits a task for execution on a single-threaded executor. It is guaranteed that tasks with the same TaskType are executed in the order of submission.
The caller is responsible for catching and handling java.util.concurrent.RejectedExecutionException if the executor is saturated.
On process termination the service will attempt to wait for previously submitted jobs with the task type TaskType.ERROR_REQUEST, TaskType.SESSION_REQUEST and TaskType.IO. This is a best-effort attempt - no guarantee can be made that the operations will complete.
-
shutdown
final Unit shutdown()
Notifies the background service that the process is about to terminate. This causes it to shutdown submission of tasks to executors, while allowing for in-flight tasks to be completed within a reasonable grace period.
-
-
-
-