Class ScheduledTaskThreadPool.SchedulableTick

java.lang.Object
ca.spottedleaf.concurrentutil.scheduler.ScheduledTaskThreadPool.SchedulableTick
Enclosing class:
ScheduledTaskThreadPool

public abstract static class ScheduledTaskThreadPool.SchedulableTick extends Object
Represents a tickable task that can be scheduled into a ScheduledTaskThreadPool.

A tickable task is expected to run on a fixed interval, which is determined by the ScheduledTaskThreadPool.

A tickable task can have intermediate tasks that can be executed before its tick method is ran. Instead of the ScheduledTaskThreadPool parking in-between ticks, the scheduler will instead drain intermediate tasks from scheduled tasks. The parsing of intermediate tasks allows the scheduler to take advantage of downtime to reduce the intermediate task load from tasks once they begin ticking.

It is guaranteed that runTick() and runTasks(BooleanSupplier) are never invoked in parallel. It is required that when intermediate tasks are scheduled, that ScheduledTaskThreadPool.notifyTasks(SchedulableTick) is invoked for any scheduled task - otherwise, runTasks(BooleanSupplier) may not be invoked to parse intermediate tasks.

  • Field Details

    • id

      public final long id
  • Constructor Details

    • SchedulableTick

      public SchedulableTick()
  • Method Details

    • getScheduledStart

      protected final long getScheduledStart()
    • setScheduledStart

      protected final void setScheduledStart(long value)
      If this task is scheduled, then this may only be invoked during runTick()
    • runTick

      public abstract boolean runTick()
      Executes the tick.

      It is the callee's responsibility to invoke setScheduledStart(long) to adjust the start of the next tick.

      Returns:
      true if the task should continue to be scheduled, false otherwise.
    • hasTasks

      public abstract boolean hasTasks()
      Returns whether this task has any intermediate tasks that can be executed.
    • runTasks

      public abstract boolean runTasks(BooleanSupplier canContinue)
      Returns:
      true if the task should continue to be scheduled, false otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object