Class ExecutorServiceCounter
java.lang.Object
edu.harvard.seas.pl.abcdatalog.util.ExecutorServiceCounter
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 Summary
ConstructorDescriptionConstructs an ExecutorServiceCounter backed by the given ExecutorService. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Blocks the calling thread until this ExecutorServiceCounter has no pending or incomplete tasks.void
Shutdowns the ExecutorService backing this ExecutorServiceCounter (i.e., so it stops accepting new tasks) and blocks until any outstanding tasks have been completed.void
submitTask
(Runnable task) Adds a task to be tracked by this ExecutorServiceCounter.
-
Constructor Details
-
ExecutorServiceCounter
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
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.
-