Interface EnhancedExecutor

All Superinterfaces:
Executor
All Known Implementing Classes:
SimplifiedEnhancedExecutor

public interface EnhancedExecutor extends Executor
A 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 Details

    • execute

      void execute(Runnable command)
      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 in ForkJoinPool.commonPool may run later on the same pooled thread.
      Specified by:
      execute in interface Executor
      Parameters:
      command - the command
    • submit

      CompletableFuture<?> submit(Runnable command)
      Execute an asynchronous action using this executor.

      The returned future provides the ability to listen for completion or block until complete.
      Parameters:
      command - the Runnable to run
      Returns:
      a future completed when the command is run
    • supply

      <T> CompletableFuture<T> supply(Supplier<T> supplier)
      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

      ScheduledTask scheduleOnce(Runnable command, Duration delay)
      Schedules a delayed task
      Parameters:
      command - the runnable to run
      delay - 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 run
      initialDelay - the initial delay before the first execution begins
      delayCalculator - 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 run
      initialDelay - the initial delay before the first execution begins
      delayCalculator - the delay calculator to calculate repeated delays
      Returns:
      a scheduled task representing the repeating work, which may be cancelled