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.

@FunctionalInterface public interface DelayCalculator
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 Type
    Method
    Description
    long
    calculateNextDelay(long previousDelayNanos, long executionTimeNanos)
    Calculates the next delay, based on the previous delay and execution time.
    default boolean
    Whether the execution time passed to calculateNextDelay(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 return true
      Parameters:
      previousDelayNanos - the previous delay, in nanoseconds
      executionTimeNanos - how long it took the task to previously execute, in nanoseconds. If requiresExecutionTime is 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 to calculateNextDelay(long, long) is used.
      Returns:
      true if the execution time is used, false otherwise