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)
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.
|
ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
command
- the task to executedelay
- the time from now to delay executionunit
- the time unit of the delay parameterget()
method will return
null
upon completionRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is null<V> ScheduledFuture<Future<V>> schedule(Callable<V> command, long delay, TimeUnit unit)
command
- the task to executedelay
- the time from now to delay executionunit
- the time unit of the delay parameterget()
method will return
<V>
upon completionRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is nullScheduledFuture<?> scheduleWithRepetition(Runnable command, long initialDelay, long period, TimeUnit unit)
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.command
- the task to executeinitialDelay
- the time to delay first executionperiod
- the period between successive executionsunit
- the time unit of the initialDelay and period parametersget()
method will throw an
exception upon cancellationRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is nullIllegalArgumentException
- if period is less than or equal to zeroCopyright © 2020 Hazelcast, Inc.. All Rights Reserved.