public final class TaskQueue extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
TaskQueue.Builder |
static interface |
TaskQueue.Task |
static class |
TaskQueue.TaskPriority |
| Constructor and Description |
|---|
TaskQueue(Executor executor)
|
TaskQueue(Executor executor,
int maxConcurrentTasks,
int maxQueueSize,
int priorityRatio)
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
execute(TaskQueue.Task task)
Queue a
TaskQueue.Task to be executed. |
boolean |
isShutdown() |
static TaskQueue.Builder |
newBuilder() |
void |
pause()
Pause execution of queued
TaskQueue.Tasks. |
void |
resume()
Resume execution of queued
TaskQueue.Tasks. |
List<TaskQueue.Task> |
shutdown(boolean awaitQuiescence)
Shut down this executor, optionally awaiting completion of any currently-executing tasks.
|
@Nullable CompletionStage<Unit> |
submit(TaskQueue.Task task)
Queue a
TaskQueue.Task to be executed, returning a CompletionStage that will
complete when the task has been executed. |
public TaskQueue(Executor executor)
TaskQueue that executes TaskQueue.Tasks on the provided Executor.
All other parameters are default values.
executor - the Executor that TaskQueue.Tasks will use to execute.DEFAULT_MAX_CONCURRENT_TASKS,
DEFAULT_MAX_QUEUE_SIZE,
DEFAULT_PRIORITY_RATIOpublic TaskQueue(Executor executor, int maxConcurrentTasks, int maxQueueSize, int priorityRatio)
executor - the Executor that TaskQueue.Tasks will use to execute.maxConcurrentTasks - the number of concurrently executing tasks allowed. When 1, the
default value, submitted Tasks are guaranteed to execute serially.maxQueueSize - the maximum number of Tasks that can be queued before backpressure
is applied and execute(Task) starts returning false.priorityRatio - ratio of TaskQueue.TaskPriority.ELEVATED tasks to
TaskQueue.TaskPriority.REGULAR tasks that will be executed when
elevated tasks are continually being dequeued.public boolean execute(TaskQueue.Task task)
TaskQueue.Task to be executed.task - the TaskQueue.Task to be executed.true if task was queued for execution, or false if it was
not queued, either because this TaskQueue is shut down, or because backpressure
is being applied because the configured max queue size would be exceeded.@Nullable public @Nullable CompletionStage<Unit> submit(TaskQueue.Task task)
TaskQueue.Task to be executed, returning a CompletionStage that will
complete when the task has been executed.
The callback completes asynchronously, using the TaskQueue's configured
Executor, and does not block execution of any further queued tasks.
task - the TaskQueue.Task to be executed.CompletionStage that will complete when task has been executed,
or null if the task was not queued, either because this TaskQueue is shut down,
or because backpressure is being applied because the configured max queue size would be
exceeded.public void pause()
TaskQueue.Tasks.public void resume()
TaskQueue.Tasks.public List<TaskQueue.Task> shutdown(boolean awaitQuiescence) throws InterruptedException
awaitQuiescence - true if this method should block awaiting completion of any
currently-executing tasks.TaskQueue.Tasks that were queued and will not be executed.InterruptedException - if the current Thread is interrupted while waiting.public boolean isShutdown()
public static TaskQueue.Builder newBuilder()
TaskQueue.Builder instance.Copyright © 2025. All rights reserved.