Package io.micronaut.scheduling
Class ScheduledExecutorTaskScheduler
java.lang.Object
io.micronaut.scheduling.ScheduledExecutorTaskScheduler
- All Implemented Interfaces:
TaskScheduler
@Named("scheduled")
@Primary
@Singleton
public class ScheduledExecutorTaskScheduler
extends Object
implements TaskScheduler
Simple abstraction over
ScheduledExecutorService
.- Since:
- 1.0
- Author:
- graemerocher
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<V> ScheduledFuture<V>
Creates and executes a one-shot action that becomes enabled after the given delay.Creates and executes a one-shot action that becomes enabled after the given delay.<V> ScheduledFuture<V>
Creates and executes a one-shot action that becomes enabled after the given delay.Creates and executes a one-shot action that becomes enabled after the given delay.<V> ScheduledFuture<V>
Creates and executes a ScheduledFuture that becomes enabled after the given delay.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 afterinitialDelay
theninitialDelay+period
, theninitialDelay + 2 * period
, and so on.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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.scheduling.TaskScheduler
schedule
-
Constructor Details
-
ScheduledExecutorTaskScheduler
- Parameters:
executorService
- To schedule executor tasks
-
-
Method Details
-
schedule
Description copied from interface:TaskScheduler
Creates and executes a one-shot action that becomes enabled after the given delay.- Specified by:
schedule
in interfaceTaskScheduler
- Parameters:
cron
- The cron expressioncommand
- the task to execute- Returns:
- a ScheduledFuture representing pending completion of
the task and whose
get()
method will returnnull
upon completion
-
schedule
Description copied from interface:TaskScheduler
Creates and executes a one-shot action that becomes enabled after the given delay.- Specified by:
schedule
in interfaceTaskScheduler
- Type Parameters:
V
- The type of the callable's result- Parameters:
cron
- The cron expressioncommand
- The task to execute- Returns:
- a ScheduledFuture representing pending completion of
the task and whose
get()
method will returnnull
upon completion
-
schedule
public <V> ScheduledFuture<V> schedule(@NonNull @NonNull String cron, @Nullable @Nullable String timezoneId, @NonNull @NonNull Callable<V> command) Description copied from interface:TaskScheduler
Creates and executes a one-shot action that becomes enabled after the given delay.- Specified by:
schedule
in interfaceTaskScheduler
- Type Parameters:
V
- The type of the callable's result- Parameters:
cron
- The cron expressiontimezoneId
- The time zone to base the cron expression on. Defaults to system time zonecommand
- The task to execute- Returns:
- a ScheduledFuture representing pending completion of
the task and whose
get()
method will returnnull
upon completion
-
schedule
Description copied from interface:TaskScheduler
Creates and executes a one-shot action that becomes enabled after the given delay.- Specified by:
schedule
in interfaceTaskScheduler
- Parameters:
delay
- the time from now to delay executioncommand
- the task to execute- Returns:
- a ScheduledFuture representing pending completion of
the task and whose
get()
method will returnnull
upon completion
-
schedule
Description copied from interface:TaskScheduler
Creates and executes a ScheduledFuture that becomes enabled after the given delay.- Specified by:
schedule
in interfaceTaskScheduler
- Type Parameters:
V
- The type of the callable's result- Parameters:
delay
- The time from now to delay executioncallable
- The function to execute- Returns:
- a ScheduledFuture that can be used to extract result or cancel
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Duration initialDelay, Duration period, Runnable command) Description copied from interface:TaskScheduler
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 afterinitialDelay
theninitialDelay+period
, theninitialDelay + 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.- Specified by:
scheduleAtFixedRate
in interfaceTaskScheduler
- Parameters:
initialDelay
- the time to delay first executionperiod
- the period between successive executionscommand
- the task to execute- Returns:
- a ScheduledFuture representing pending completion of
the task, and whose
get()
method will throw an exception upon cancellation
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Duration initialDelay, Duration delay, Runnable command) Description copied from interface:TaskScheduler
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. 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.- Specified by:
scheduleWithFixedDelay
in interfaceTaskScheduler
- Parameters:
initialDelay
- the time to delay first executiondelay
- the delay between the termination of onecommand
- the task to execute execution and the commencement of the next- Returns:
- a ScheduledFuture representing pending completion of
the task, and whose
get()
method will throw an exception upon cancellation
-