Class ExecutorServiceCounter

java.lang.Object
edu.harvard.seas.pl.abcdatalog.util.ExecutorServiceCounter

public class ExecutorServiceCounter extends Object
A wrapper for an executor service that tracks how many tasks are either pending or incomplete, and can be used to block until all tasks have finished.
  • Constructor Details

    • ExecutorServiceCounter

      public ExecutorServiceCounter(ExecutorService exec)
      Constructs an ExecutorServiceCounter backed by the given ExecutorService. The supplied ExecutorService should only be accessed via the ExecutorServiceCounter.
      Parameters:
      exec - the ExecutorService to back the ExecutorServiceCounter
  • Method Details

    • submitTask

      public void submitTask(Runnable task)
      Adds a task to be tracked by this ExecutorServiceCounter. If this method is invoked from a ForkJoinPool worker thread, the task is forked in that ForkJoinPool. Otherwise, it is submitted to the ExecutorService backing this ExecutorServiceCounter.
      Parameters:
      task - the task
    • blockUntilFinished

      public void blockUntilFinished()
      Blocks the calling thread until this ExecutorServiceCounter has no pending or incomplete tasks.
    • shutdownAndAwaitTermination

      public void shutdownAndAwaitTermination()
      Shutdowns the ExecutorService backing this ExecutorServiceCounter (i.e., so it stops accepting new tasks) and blocks until any outstanding tasks have been completed.