Annotation Type ScheduleWithFixedDelay


  • @Documented
    @Retention(RUNTIME)
    @Target(TYPE)
    public @interface ScheduleWithFixedDelay
    Schedules the method to run with fixed delay, automatically.

    For example, you want a method to do something every minute:

     @ScheduleWithFixedDelay(delay = 1, unit = TimeUnit.MINUTES)
     public class Bucket implements Runnable, Closeable {
       @Override
       void run() {
         // do some routine job
       }
       @Override
       void close() {
         // close operations
       }
     }

    Execution will be started as soon as you make an instance of the class, and will be stopped when you call close():

     Bucket bucket = new Bucket();
     // some time later
     bucket.close();

    In order to be executed the class should implement either Runnable or Callable. In order to be closed and stopped, your the class should implement Closeable and its close() method should be explicitly called at the moment you want it to stop.

    NOTE: It should be pointed out that in order to ensure that there are no duplicate executions, you can only schedule an execution once between all equal objects (i.e. instances that are equal as per Object.equals(Object))). Invoking the same method multiple times, without stopping it first, will result in an IllegalStateException being thrown.

    Since:
    0.7.16
    See Also:
    http://aspects.jcabi.com/
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      int await
      How long to wait for the task to finish after shutdown in await units.
      TimeUnit awaitUnit
      Time units of await time.
      int delay
      Delay, in time units.
      int shutdownAttempts
      How many times to do a forceful shutdown after await time.
      int threads
      Total number of fixed threads.
      TimeUnit unit
      Time units of delay.
      boolean verbose
      Be less verbose.
    • Element Detail

      • delay

        int delay
        Delay, in time units.
        Returns:
        The delay time amount
        Default:
        1
      • unit

        TimeUnit unit
        Time units of delay.
        Returns:
        The time unit
        Default:
        java.util.concurrent.TimeUnit.MINUTES
      • await

        int await
        How long to wait for the task to finish after shutdown in await units.
        Returns:
        The await time amount
        Default:
        1
      • awaitUnit

        TimeUnit awaitUnit
        Time units of await time.
        Returns:
        The await time unit
        Default:
        java.util.concurrent.TimeUnit.MINUTES
      • shutdownAttempts

        int shutdownAttempts
        How many times to do a forceful shutdown after await time. Each forceful shutdown attempt will be followed by a 1 second wait to allow the threads to finish.
        Returns:
        The number if times
        Default:
        1
      • threads

        int threads
        Total number of fixed threads.
        Returns:
        The number of threads
        Default:
        1
      • verbose

        boolean verbose
        Be less verbose.
        Returns:
        The flag
        Default:
        true