Class WorkQueue<T>

java.lang.Object
nonapi.io.github.classgraph.concurrency.WorkQueue<T>
Type Parameters:
T - The work unit type.
All Implemented Interfaces:
AutoCloseable

public class WorkQueue<T> extends Object implements AutoCloseable
A parallel work queue.
  • Method Details

    • runWorkQueue

      public static <U> void runWorkQueue(Collection<U> elements, ExecutorService executorService, InterruptionChecker interruptionChecker, int numParallelTasks, LogNode log, WorkQueue.WorkUnitProcessor<U> workUnitProcessor) throws InterruptedException, ExecutionException
      Start a work queue on the elements in the provided collection, blocking until all work units have been completed.
      Type Parameters:
      U - The type of the work queue units.
      Parameters:
      elements - The work queue units to process.
      executorService - The ExecutorService.
      interruptionChecker - the interruption checker
      numParallelTasks - The number of parallel tasks.
      log - The log.
      workUnitProcessor - The WorkQueue.WorkUnitProcessor.
      Throws:
      InterruptedException - If the work was interrupted.
      ExecutionException - If a worker throws an uncaught exception.
    • addWorkUnit

      public void addWorkUnit(T workUnit)
      Add a unit of work. May be called by workers to add more work units to the tail of the queue.
      Parameters:
      workUnit - the work unit
      Throws:
      NullPointerException - if the work unit is null.
    • addWorkUnits

      public void addWorkUnits(Collection<T> workUnits)
      Add multiple units of work. May be called by workers to add more work units to the tail of the queue.
      Parameters:
      workUnits - The work units to add to the tail of the queue.
      Throws:
      NullPointerException - if any of the work units are null.
    • close

      public void close() throws ExecutionException
      Completion barrier for work queue. This should be called after runWorkLoop() exits on the main thread (e.g. using try-with-resources).
      Specified by:
      close in interface AutoCloseable
      Throws:
      ExecutionException - If a worker threw an uncaught exception.