Interface EnhancedExecutor
- All Superinterfaces:
Executor
- All Known Implementing Classes:
SimplifiedEnhancedExecutor
A
Methods come in 3 categories: basic execution, one time delayed tasks, and repeating tasks. Delays are specified in
No method may return
Basic Usage
For basic asynchronous work,
Delayed Scheduling
Repeated Scheduling
The scheduleRepeating methods provide repeated scheduling. Cancellation will prevent future executions of the task from beginning, but in-progress work will not be cancelled.
Each method takes a
No executions may ever overlap. That is, the next execution of a task will never commence while an existing execution is in progress.
Executor with upgraded concurrent functionality. Focuses
specifically on concurrent execution and scheduling, and as such there are no
methods for thread pool management (such as shutdown, await termination,
etc.) as in ExecutorService. Methods come in 3 categories: basic execution, one time delayed tasks, and repeating tasks. Delays are specified in
Duration. No method may return
null. No parameters may ever be null,
and NullPointerException will be thrown otherwise. Basic Usage
For basic asynchronous work,
execute(Runnable),
submit(Runnable), and supply(Supplier) may be used. Delayed Scheduling
scheduleOnce(Runnable, Duration) provides delayed scheduling. The
delay is provided as a Duration. Returned ScheduledTasks may
be used to cancel the task before it begins execution. Repeated Scheduling
The scheduleRepeating methods provide repeated scheduling. Cancellation will prevent future executions of the task from beginning, but in-progress work will not be cancelled.
Each method takes a
DelayCalculator whose responsibility it is to
calculate the next delay, based on both the previous delay and the execution
time. DelayCalculators may be used for common useful implementations
of such interface. The DelayCalculator calculating a negative delay
is equivalent to cancellation of the ScheduledTask. No executions may ever overlap. That is, the next execution of a task will never commence while an existing execution is in progress.
- Author:
- A248
-
Method Summary
Modifier and TypeMethodDescriptionvoidExecutes an asynchronous action.scheduleOnce(Runnable command, Duration delay) Schedules a delayed taskscheduleRepeating(Runnable command, Duration initialDelay, DelayCalculator delayCalculator) Schedules a repeating taskscheduleRepeating(Consumer<? super ScheduledTask> command, Duration initialDelay, DelayCalculator delayCalculator) Schedules a repeating taskExecute an asynchronous action using this executor.<T> CompletableFuture<T> Supplies a value asynchronously using this executor.
-
Method Details
-
execute
Executes an asynchronous action.
The command may execute in the calling thread, but not synchronously. For example, actions submitted from within one of the threads inForkJoinPool.commonPoolmay run later on the same pooled thread. -
submit
Execute an asynchronous action using this executor.
The returned future provides the ability to listen for completion or block until complete.- Parameters:
command- theRunnableto run- Returns:
- a future completed when the command is run
-
supply
Supplies a value asynchronously using this executor.- Type Parameters:
T- the type of the supplier- Parameters:
supplier- the supplier- Returns:
- a future which yields the result of the supplier
-
scheduleOnce
Schedules a delayed task- Parameters:
command- the runnable to rundelay- the duration after which to commence execution- Returns:
- a scheduled task for the delayed work, which may be cancelled before execution begins
-
scheduleRepeating
ScheduledTask scheduleRepeating(Runnable command, Duration initialDelay, DelayCalculator delayCalculator) Schedules a repeating task- Parameters:
command- the runnable to runinitialDelay- the initial delay before the first execution beginsdelayCalculator- the delay calculator to calculate repeated delays- Returns:
- a scheduled task for the repeating work, which may be cancelled
-
scheduleRepeating
ScheduledTask scheduleRepeating(Consumer<? super ScheduledTask> command, Duration initialDelay, DelayCalculator delayCalculator) Schedules a repeating task- Parameters:
command- the consumer to runinitialDelay- the initial delay before the first execution beginsdelayCalculator- the delay calculator to calculate repeated delays- Returns:
- a scheduled task representing the repeating work, which may be cancelled
-