Class ScheduledExecutorTaskScheduler

  • All Implemented Interfaces:
    TaskScheduler

    @Named("scheduled")
    @Primary
    @Singleton
    public class ScheduledExecutorTaskScheduler
    extends java.lang.Object
    implements TaskScheduler
    Simple abstraction over ScheduledExecutorService.
    Since:
    1.0
    • Method Summary

      All Methods Instance Methods Concrete 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.
      <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 after initialDelay then initialDelay+period, then initialDelay + 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ScheduledExecutorTaskScheduler

        public ScheduledExecutorTaskScheduler​(@Named("scheduled")
                                              java.util.concurrent.ExecutorService executorService)
        Parameters:
        executorService - To schedule executor tasks
    • Method Detail

      • schedule

        public java.util.concurrent.ScheduledFuture<?> schedule​(java.lang.String cron,
                                                                java.lang.Runnable command)
        Description copied from interface: TaskScheduler
        Creates and executes a one-shot action that becomes enabled after the given delay.
        Specified by:
        schedule in interface TaskScheduler
        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
      • schedule

        public <V> java.util.concurrent.ScheduledFuture<V> schedule​(java.lang.String cron,
                                                                    java.util.concurrent.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 interface TaskScheduler
        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
      • schedule

        public <V> java.util.concurrent.ScheduledFuture<V> schedule​(@NonNull
                                                                    java.lang.String cron,
                                                                    @Nullable
                                                                    java.lang.String timezoneId,
                                                                    @NonNull
                                                                    java.util.concurrent.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 interface TaskScheduler
        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
      • schedule

        public java.util.concurrent.ScheduledFuture<?> schedule​(java.time.Duration delay,
                                                                java.lang.Runnable command)
        Description copied from interface: TaskScheduler
        Creates and executes a one-shot action that becomes enabled after the given delay.
        Specified by:
        schedule in interface TaskScheduler
        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
      • schedule

        public <V> java.util.concurrent.ScheduledFuture<V> schedule​(java.time.Duration delay,
                                                                    java.util.concurrent.Callable<V> callable)
        Description copied from interface: TaskScheduler
        Creates and executes a ScheduledFuture that becomes enabled after the given delay.
        Specified by:
        schedule in interface TaskScheduler
        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
      • scheduleAtFixedRate

        public java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate​(java.time.Duration initialDelay,
                                                                           java.time.Duration period,
                                                                           java.lang.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 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.
        Specified by:
        scheduleAtFixedRate in interface TaskScheduler
        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
      • scheduleWithFixedDelay

        public java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay​(java.time.Duration initialDelay,
                                                                              java.time.Duration delay,
                                                                              java.lang.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 interface TaskScheduler
        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