Interface DelayCalculator
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A delay calculator which calculates the next delay of a task based on both
the previous delay and the execution time.
- Author:
- A248
-
Method Summary
Modifier and TypeMethodDescriptionlongcalculateNextDelay(long previousDelayNanos, long executionTimeNanos) Calculates the next delay, based on the previous delay and execution time.default booleanWhether the execution time passed tocalculateNextDelay(long, long)is used.
-
Method Details
-
calculateNextDelay
long calculateNextDelay(long previousDelayNanos, long executionTimeNanos) Calculates the next delay, based on the previous delay and execution time.
If the returned duration is negative, the task will be cancelled. If zero, it will run immediately.
The execution time is not computed by default. If the execution time is used by this calculator,requiresExecutionTime()should returntrue- Parameters:
previousDelayNanos- the previous delay, in nanosecondsexecutionTimeNanos- how long it took the task to previously execute, in nanoseconds. IfrequiresExecutionTimeis false, this will be 0- Returns:
- the next delay in nanoseconds, negative to cancel the task, zero to run immediately
-
requiresExecutionTime
default boolean requiresExecutionTime()Whether the execution time passed tocalculateNextDelay(long, long)is used.- Returns:
- true if the execution time is used, false otherwise
-