@Named(value="scheduled") @Primary @Singleton public class ScheduledExecutorTaskScheduler extends Object implements TaskScheduler
ScheduledExecutorService
.Constructor and Description |
---|
ScheduledExecutorTaskScheduler(ExecutorService executorService) |
Modifier and Type | Method and Description |
---|---|
<V> ScheduledFuture<V> |
schedule(Duration delay,
Callable<V> callable)
Creates and executes a ScheduledFuture that becomes enabled after the
given delay.
|
ScheduledFuture<?> |
schedule(Duration delay,
Runnable command)
Creates and executes a one-shot action that becomes enabled
after the given delay.
|
<V> ScheduledFuture<V> |
schedule(String cron,
Callable<V> command)
Creates and executes a one-shot action that becomes enabled
after the given delay.
|
ScheduledFuture<?> |
schedule(String cron,
Runnable command)
Creates and executes a one-shot action that becomes enabled
after the given delay.
|
ScheduledFuture<?> |
scheduleAtFixedRate(Duration initialDelay,
Duration period,
Runnable command)
Creates and executes a periodic action that becomes enabled first
after the given initial delay, and subsequently with the given
period; that is executions will commence after
initialDelay then initialDelay+period , then
initialDelay + 2 * period , and so on. |
ScheduledFuture<?> |
scheduleWithFixedDelay(Duration initialDelay,
Duration delay,
Runnable command)
Creates and executes a periodic action that becomes enabled first
after the given initial delay, and subsequently with the
given delay between the termination of one execution and the
commencement of the next.
|
public ScheduledExecutorTaskScheduler(@Named(value="scheduled") ExecutorService executorService)
executorService
- To schedule executor taskspublic ScheduledFuture<?> schedule(String cron, Runnable command)
TaskScheduler
schedule
in interface TaskScheduler
cron
- The cron expressioncommand
- the task to executeget()
method will return
null
upon completionpublic <V> ScheduledFuture<V> schedule(String cron, Callable<V> command)
TaskScheduler
schedule
in interface TaskScheduler
V
- The type of the callable's resultcron
- The cron expressioncommand
- The task to executeget()
method will return
null
upon completionpublic ScheduledFuture<?> schedule(Duration delay, Runnable command)
TaskScheduler
schedule
in interface TaskScheduler
delay
- the time from now to delay executioncommand
- the task to executeget()
method will return
null
upon completionpublic <V> ScheduledFuture<V> schedule(Duration delay, Callable<V> callable)
TaskScheduler
schedule
in interface TaskScheduler
V
- The type of the callable's resultdelay
- The time from now to delay executioncallable
- The function to executepublic ScheduledFuture<?> scheduleAtFixedRate(Duration initialDelay, Duration period, Runnable command)
TaskScheduler
initialDelay
then initialDelay+period
, then
initialDelay + 2 * period
, and so on.
If any execution of the task
encounters an exception, subsequent executions are suppressed.
Otherwise, the task will only terminate via cancellation or
termination of the executor. If any execution of this task
takes longer than its period, then subsequent executions
may start late, but will not concurrently execute.scheduleAtFixedRate
in interface TaskScheduler
initialDelay
- the time to delay first executionperiod
- the period between successive executionscommand
- the task to executeget()
method will throw an
exception upon cancellationpublic ScheduledFuture<?> scheduleWithFixedDelay(Duration initialDelay, Duration delay, Runnable command)
TaskScheduler
scheduleWithFixedDelay
in interface TaskScheduler
initialDelay
- the time to delay first executiondelay
- the delay between the termination of onecommand
- the task to execute
execution and the commencement of the nextget()
method will throw an
exception upon cancellation