Package io.micronaut.scheduling
Interface TaskScheduler
-
- All Known Implementing Classes:
ScheduledExecutorTaskScheduler
public interface TaskScheduler
Interface for Scheduling tasks.- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.concurrent.ScheduledFuture<?>
schedule(java.lang.String cron, java.lang.Runnable command)
Creates and executes a one-shot action that becomes enabled after the given delay.default java.util.concurrent.ScheduledFuture<?>
schedule(java.lang.String cron, java.lang.String timezoneId, java.lang.Runnable command)
Creates and executes a one-shot action that becomes enabled after the given delay.default <V> java.util.concurrent.ScheduledFuture<V>
schedule(java.lang.String cron, java.lang.String timezoneId, java.util.concurrent.Callable<V> command)
Creates and executes a one-shot action that becomes enabled after the given delay.<V> java.util.concurrent.ScheduledFuture<V>
schedule(java.lang.String cron, java.util.concurrent.Callable<V> command)
Creates and executes a one-shot action that becomes enabled after the given delay.java.util.concurrent.ScheduledFuture<?>
schedule(java.time.Duration delay, java.lang.Runnable command)
Creates and executes a one-shot action that becomes enabled after the given delay.<V> java.util.concurrent.ScheduledFuture<V>
schedule(java.time.Duration delay, java.util.concurrent.Callable<V> callable)
Creates and executes a ScheduledFuture that becomes enabled after the given delay.java.util.concurrent.ScheduledFuture<?>
scheduleAtFixedRate(java.time.Duration initialDelay, java.time.Duration period, java.lang.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.java.util.concurrent.ScheduledFuture<?>
scheduleWithFixedDelay(java.time.Duration initialDelay, java.time.Duration delay, java.lang.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.
-
-
-
Method Detail
-
schedule
java.util.concurrent.ScheduledFuture<?> schedule(java.lang.String cron, java.lang.Runnable command)
Creates and executes a one-shot action that becomes enabled after the given delay.- 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 - Throws:
java.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if command or delay is null
-
schedule
<V> java.util.concurrent.ScheduledFuture<V> schedule(java.lang.String cron, java.util.concurrent.Callable<V> command)
Creates and executes a one-shot action that becomes enabled after the given delay.- 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 - Throws:
java.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if command or delay is null
-
schedule
default java.util.concurrent.ScheduledFuture<?> schedule(@NonNull java.lang.String cron, @Nullable java.lang.String timezoneId, @NonNull java.lang.Runnable command)
Creates and executes a one-shot action that becomes enabled after the given delay.- Parameters:
cron
- The cron expressiontimezoneId
- The timezoneId 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 - Throws:
java.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if command or delay is null
-
schedule
default <V> java.util.concurrent.ScheduledFuture<V> schedule(@NonNull java.lang.String cron, @Nullable java.lang.String timezoneId, @NonNull java.util.concurrent.Callable<V> command)
Creates and executes a one-shot action that becomes enabled after the given delay.- 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 - Throws:
java.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if command or delay is null
-
schedule
java.util.concurrent.ScheduledFuture<?> schedule(java.time.Duration delay, java.lang.Runnable command)
Creates and executes a one-shot action that becomes enabled after the given delay.- 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 - Throws:
java.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if command or delay is null
-
schedule
<V> java.util.concurrent.ScheduledFuture<V> schedule(java.time.Duration delay, java.util.concurrent.Callable<V> callable)
Creates and executes a ScheduledFuture that becomes enabled after the given delay.- 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
- Throws:
java.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if callable or delay is null
-
scheduleAtFixedRate
java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate(@Nullable java.time.Duration initialDelay, java.time.Duration period, java.lang.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. 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.- 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 - Throws:
java.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if command or period is nulljava.lang.IllegalArgumentException
- if period less than or equal to zero
-
scheduleWithFixedDelay
java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay(@Nullable java.time.Duration initialDelay, java.time.Duration delay, java.lang.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. 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.- 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 - Throws:
java.util.concurrent.RejectedExecutionException
- if the task cannot be scheduled for executionjava.lang.NullPointerException
- if command or delay is nulljava.lang.IllegalArgumentException
- if delay less than or equal to zero
-
-