Class SerialTaskExecutor

java.lang.Object
com.jozufozu.flywheel.impl.task.SerialTaskExecutor
All Implemented Interfaces:
TaskExecutor, Executor

public class SerialTaskExecutor extends Object implements TaskExecutor
  • Field Details

  • Method Details

    • execute

      public void execute(Runnable task)
      Specified by:
      execute in interface Executor
    • scheduleForMainThread

      public void scheduleForMainThread(Runnable runnable)
      Description copied from interface: TaskExecutor
      Schedule a task to be run on the main thread.
      This method may be called from any thread (including the main thread), but the runnable will only be executed once somebody calls either TaskExecutor.syncPoint() or TaskExecutor.syncUntil(BooleanSupplier) on this task executor's main thread.
      Specified by:
      scheduleForMainThread in interface TaskExecutor
      Parameters:
      runnable - The task to run.
    • syncPoint

      public void syncPoint()
      Description copied from interface: TaskExecutor
      Wait for all running tasks to finish.
      This is useful as a nuclear option, but most of the time you should try to use syncUntil.
      Specified by:
      syncPoint in interface TaskExecutor
    • syncUntil

      public boolean syncUntil(BooleanSupplier cond)
      Description copied from interface: TaskExecutor
      Wait for running tasks, until the given condition is met (BooleanSupplier.getAsBoolean() returns true).
      This method is equivalent to syncWhile(() -> !cond.getAsBoolean()).
      Specified by:
      syncUntil in interface TaskExecutor
      Parameters:
      cond - The condition to wait for.
      Returns:
      true if the condition is met. false if this executor runs out of tasks before the condition is met.
    • syncWhile

      public boolean syncWhile(BooleanSupplier cond)
      Description copied from interface: TaskExecutor
      Wait for running tasks, so long as the given condition is met (BooleanSupplier.getAsBoolean() returns true).
      If this method is called on the
      This method is equivalent to syncUntil(() -> !cond.getAsBoolean()).
      Specified by:
      syncWhile in interface TaskExecutor
      Parameters:
      cond - The condition sync on.
      Returns:
      true if the condition is no longer met. false if this executor runs out of tasks while the condition is still met.
    • threadCount

      public int threadCount()
      Description copied from interface: TaskExecutor
      Check for the number of threads this executor uses.
      May be helpful when determining how many chunks to divide a task into.
      Specified by:
      threadCount in interface TaskExecutor
      Returns:
      The number of threads this executor uses.
    • isMainThread

      public boolean isMainThread()
      Description copied from interface: TaskExecutor
      Check whether the current thread is this task executor's main thread.
      Specified by:
      isMainThread in interface TaskExecutor
      Returns:
      true if the current thread is the main thread.