Class ParallelTaskExecutor

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

public class ParallelTaskExecutor extends Object implements TaskExecutor
  • Constructor Details

    • ParallelTaskExecutor

      public ParallelTaskExecutor(String name, int threadCount, BooleanSupplier mainThreadQuery)
  • Method Details

    • 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.
    • startWorkers

      public void startWorkers()
      Spawns a number of work-stealing threads to process results in the task queue. If the executor is already running, this method does nothing and exits.
    • stopWorkers

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

      public void syncPoint()
      Wait for all running tasks to finish.
      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.