Interface TaskExecutor

All Superinterfaces:
Executor
All Known Implementing Classes:
ParallelTaskExecutor, SerialTaskExecutor

@NonExtendable public interface TaskExecutor extends Executor
  • Method Details

    • syncPoint

      void syncPoint()
      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.
    • syncUntil

      boolean syncUntil(BooleanSupplier cond)
      Wait for running tasks, until the given condition is met (BooleanSupplier.getAsBoolean() returns true).
      This method is equivalent to syncWhile(() -> !cond.getAsBoolean()).
      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

      boolean syncWhile(BooleanSupplier cond)
      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()).
      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.
    • scheduleForMainThread

      void scheduleForMainThread(Runnable runnable)
      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 syncPoint() or syncUntil(BooleanSupplier) on this task executor's main thread.
      Parameters:
      runnable - The task to run.
    • isMainThread

      boolean isMainThread()
      Check whether the current thread is this task executor's main thread.
      Returns:
      true if the current thread is the main thread.
    • threadCount

      int threadCount()
      Check for the number of threads this executor uses.
      May be helpful when determining how many chunks to divide a task into.
      Returns:
      The number of threads this executor uses.