public class LimitedExecutor extends Object implements Executor
maxConcurrentTasks tasks running at the same
time.
A task can finish running without allowing another task to run in its stead, with executeAsync(Supplier).
A new task will only start after the CompletableFuture returned by the task has completed.
Blocking mode. If the executor is a WithinThreadExecutor, tasks will run in the thread that
submitted them. If there are no available permits, the caller thread will block until a permit becomes available.
| Constructor and Description |
|---|
LimitedExecutor(String name,
Executor executor,
int maxConcurrentTasks) |
| Modifier and Type | Method and Description |
|---|---|
void |
execute(Runnable command) |
void |
executeAsync(Supplier<CompletionStage<Void>> asyncCommand)
Similar to
execute(Runnable), but the task can continue executing asynchronously,
without blocking the OS thread, while still counting against this executor's limit. |
void |
shutdownNow()
Stops the executor and cancels any queued tasks.
|
public void shutdownNow()
public void executeAsync(Supplier<CompletionStage<Void>> asyncCommand)
execute(Runnable), but the task can continue executing asynchronously,
without blocking the OS thread, while still counting against this executor's limit.asyncCommand - A task that returns a non-null CompletionStage,
which may be already completed or may complete at some point in the future.Copyright © 2022 JBoss by Red Hat. All rights reserved.