Interface Scheduler.Worker

All Superinterfaces:
Disposable
Enclosing interface:
Scheduler

public static interface Scheduler.Worker extends Disposable
A worker representing an asynchronous boundary that executes tasks.
Author:
Stephane Maldini, Simon Baslé
  • Method Details

    • schedule

      Disposable schedule(Runnable task)
      Schedules the task for immediate execution on this worker.
      Parameters:
      task - the task to schedule
      Returns:
      the Disposable instance that lets one cancel this particular task. If the Scheduler has been shut down, a RejectedExecutionException is thrown.
    • schedule

      default Disposable schedule(Runnable task, long delay, TimeUnit unit)
      Schedules the execution of the given task with the given delay amount.

      This method is safe to be called from multiple threads and tasks are executed in some total order. Two tasks scheduled at the same time with the same delay will be ordered in FIFO order if the schedule() was called from the same thread or in arbitrary order if the schedule() was called from different threads.

      Parameters:
      task - the task to schedule
      delay - the delay amount, non-positive values indicate non-delayed scheduling
      unit - the unit of measure of the delay amount
      Returns:
      the Disposable that lets one cancel this particular delayed task, or throw a RejectedExecutionException if the Worker is not capable of scheduling with delay.
    • schedulePeriodically

      default Disposable schedulePeriodically(Runnable task, long initialDelay, long period, TimeUnit unit)
      Schedules a periodic execution of the given task with the given initial delay and period.

      This method is safe to be called from multiple threads.

      The periodic execution is at a fixed rate, that is, the first execution will be after the initial delay, the second after initialDelay + period, the third after initialDelay + 2 * period, and so on.

      Parameters:
      task - the task to schedule
      initialDelay - the initial delay amount, non-positive values indicate non-delayed scheduling
      period - the period at which the task should be re-executed
      unit - the unit of measure of the delay amount
      Returns:
      the Disposable that lets one cancel this particular delayed task, or throw a RejectedExecutionException if the Worker is not capable of scheduling periodically.