Interface TaskScheduler

All Known Implementing Classes:
ScheduledExecutorTaskScheduler

public interface TaskScheduler
Interface for Scheduling tasks.
Since:
1.0
Author:
graemerocher
  • Method Details

    • schedule

      ScheduledFuture<?> schedule(String cron, Runnable command)
      Creates and executes a one-shot action that becomes enabled after the given delay.
      Parameters:
      cron - The cron expression
      command - the task to execute
      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 or delay is null
    • schedule

      <V> ScheduledFuture<V> schedule(String cron, 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 expression
      command - The task to execute
      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 or delay is null
    • schedule

      default ScheduledFuture<?> schedule(@NonNull @NonNull String cron, @Nullable @Nullable String timezoneId, @NonNull @NonNull Runnable command)
      Creates and executes a one-shot action that becomes enabled after the given delay.
      Parameters:
      cron - The cron expression
      timezoneId - The timezoneId to base the cron expression on. Defaults to system time zone
      command - the task to execute
      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 or delay is null
    • schedule

      default <V> ScheduledFuture<V> schedule(@NonNull @NonNull String cron, @Nullable @Nullable String timezoneId, @NonNull @NonNull 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 expression
      timezoneId - The time zone to base the cron expression on. Defaults to system time zone
      command - The task to execute
      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 or delay is null
    • schedule

      ScheduledFuture<?> schedule(Duration delay, Runnable command)
      Creates and executes a one-shot action that becomes enabled after the given delay.
      Parameters:
      delay - the time from now to delay execution
      command - the task to execute
      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 or delay is null
    • schedule

      <V> ScheduledFuture<V> schedule(Duration delay, 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 execution
      callable - The function to execute
      Returns:
      a ScheduledFuture that can be used to extract result or cancel
      Throws:
      RejectedExecutionException - if the task cannot be scheduled for execution
      NullPointerException - if callable or delay is null
    • scheduleAtFixedRate

      ScheduledFuture<?> scheduleAtFixedRate(@Nullable @Nullable 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. 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 execution
      period - the period between successive executions
      command - the task to execute
      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 or period is null
      IllegalArgumentException - if period less than or equal to zero
    • scheduleWithFixedDelay

      ScheduledFuture<?> scheduleWithFixedDelay(@Nullable @Nullable 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. 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 execution
      delay - the delay between the termination of one
      command - 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:
      RejectedExecutionException - if the task cannot be scheduled for execution
      NullPointerException - if command or delay is null
      IllegalArgumentException - if delay less than or equal to zero