com.hazelcast.spi

## Interface TaskScheduler

- All Superinterfaces:
    Executor
  All Known Subinterfaces:
    ClientExecutionService

      public interface TaskScheduler
      extends Executor

  `ExecutorService` can schedule a command to run after a given delay or execute periodically. The `scheduleWithRepetition(Runnable, long, long, TimeUnit)` has similar semantic to `ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit)`. It guarantees a task won't be executed by multiple threads concurrently. The difference is that this service will skip a scheduled execution if another thread is still running the same task, instead of postponing its execution. To emphasize this difference the method is called `scheduleWithRepetition` instead of `scheduleAtFixedRate` The other difference is this service does not offer an equivalent of `ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit)`

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `<V> ScheduledFuture<Future<V>>` | `schedule(Callable<V> command, long delay, TimeUnit unit)` Creates and executes a one-shot action that becomes enabled after the given delay.
    `ScheduledFuture<?>` | `schedule(Runnable command, long delay, TimeUnit unit)` Creates and executes a one-shot action that becomes enabled after the given delay.
    `ScheduledFuture<?>` | `scheduleWithRepetition(Runnable command, long initialDelay, long period, TimeUnit unit)` Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period.

    - ### Methods inherited from interface java.util.concurrent.Executor

      `execute`

- - ### Method Detail

    - #### schedule

          ScheduledFuture<?> schedule(Runnable command,
                                      long delay,
                                      TimeUnit unit)

      Creates and executes a one-shot action that becomes enabled after the given delay.
      Parameters:
        `command` - the task to execute
        `delay` - the time from now to delay execution
        `unit` - the time unit of the delay parameter
      Returns:
        a ScheduledFuture representing pending completion of the task and whose `get()` method will return `null` upon completion
      Throws:
        `RejectedExecutionException` - if the task cannot be scheduled for execution
        `NullPointerException` - if command is null

    - #### schedule

          <V> ScheduledFuture<Future<V>> schedule(Callable<V> command,
                                                  long delay,
                                                  TimeUnit unit)

      Creates and executes a one-shot action that becomes enabled after the given delay.
      Parameters:
        `command` - the task to execute
        `delay` - the time from now to delay execution
        `unit` - the time unit of the delay parameter
      Returns:
        a ScheduledFuture representing pending completion of the task and whose `get()` method will return `<V>` upon completion
      Throws:
        `RejectedExecutionException` - if the task cannot be scheduled for execution
        `NullPointerException` - if command is null

    - #### scheduleWithRepetition

          ScheduledFuture<?> scheduleWithRepetition(Runnable command,
                                                    long initialDelay,
                                                    long period,
                                                    TimeUnit unit)

      Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period. Executions will commence after `initialDelay` then `initialDelay+period`, then `initialDelay + 2 * period`, and so on. If any execution of this task takes longer than its period, then subsequent execution will be skipped.
      Parameters:
        `command` - the task to execute
        `initialDelay` - the time to delay first execution
        `period` - the period between successive executions
        `unit` - the time unit of the initialDelay and period parameters
      Returns:
        a ScheduledFuture representing pending completion of the task, and whose `get()` method will throw an exception upon cancellation
      Throws:
        `RejectedExecutionException` - if the task cannot be scheduled for execution
        `NullPointerException` - if command is null
        `IllegalArgumentException` - if period is less than or equal to zero

Copyright © 2019. All rights reserved.