Class Pacer
- java.lang.Object
-
- com.github.benmanes.caffeine.cache.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
-
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.
-
-
-
Field Detail
-
TOLERANCE
static final long TOLERANCE
-
scheduler
final Scheduler scheduler
-
nextFireTime
long nextFireTime
-
future
@Nullable java.util.concurrent.Future<?> future
-
-
Constructor Detail
-
Pacer
Pacer(Scheduler scheduler)
-
-
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.
-
-