Class Pacer


  • final class Pacer
    extends java.lang.Object
    A pacing scheduler that prevents executions from happening too frequently. Only one task may be scheduled at any given time, the earliest pending task takes precedence, and the delay may be increased if it is less than a tolerance threshold.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) @Nullable java.util.concurrent.Future<?> future  
      (package private) long nextFireTime  
      (package private) Scheduler scheduler  
      (package private) static long TOLERANCE  
    • Constructor Summary

      Constructors 
      Constructor Description
      Pacer​(Scheduler scheduler)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) long calculateSchedule​(long now, long delay, long scheduleAt)
      Returns the delay and sets the next fire time.
      void cancel()
      Attempts to cancel execution of the scheduled task, if present.
      (package private) boolean maySkip​(long scheduleAt)
      Returns if the current fire time is sooner, or if it is later and within the tolerance limit.
      void schedule​(java.util.concurrent.Executor executor, java.lang.Runnable command, long now, long delay)
      Schedules the task, pacing the execution if occurring too often.
      • Methods inherited from class java.lang.Object

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

      • TOLERANCE

        static final long TOLERANCE
      • nextFireTime

        long nextFireTime
      • future

        @Nullable java.util.concurrent.Future<?> future
    • Constructor Detail

    • Method Detail

      • schedule

        public void schedule​(java.util.concurrent.Executor executor,
                             java.lang.Runnable command,
                             long now,
                             long delay)
        Schedules the task, pacing the execution if occurring too often.
      • cancel

        public void cancel()
        Attempts to cancel execution of the scheduled task, if present.
      • maySkip

        boolean maySkip​(long scheduleAt)
        Returns if the current fire time is sooner, or if it is later and within the tolerance limit.
      • calculateSchedule

        long calculateSchedule​(long now,
                               long delay,
                               long scheduleAt)
        Returns the delay and sets the next fire time.