Class Pacer

java.lang.Object
com.github.benmanes.caffeine.cache.Pacer

final class Pacer extends 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 Future<?>
     
    (package private) long
     
    (package private) final Scheduler
     
    (package private) static final long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Pacer(Scheduler scheduler)
     
  • Method Summary

    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
    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(Executor executor, 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 Details

    • TOLERANCE

      static final long TOLERANCE
    • scheduler

      final Scheduler scheduler
    • nextFireTime

      long nextFireTime
    • future

      @Nullable Future<?> future
  • Constructor Details

  • Method Details

    • schedule

      public void schedule(Executor executor, 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.