Class WorkQueue<T>
java.lang.Object
nonapi.io.github.classgraph.concurrency.WorkQueue<T>
- Type Parameters:
T- The work unit type.
- All Implemented Interfaces:
AutoCloseable
A parallel work queue.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA work unit processor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddWorkUnit(T workUnit) Add a unit of work.voidaddWorkUnits(Collection<T> workUnits) Add multiple units of work.voidclose()Completion barrier for work queue.static <U> voidrunWorkQueue(Collection<U> elements, ExecutorService executorService, InterruptionChecker interruptionChecker, int numParallelTasks, LogNode log, WorkQueue.WorkUnitProcessor<U> workUnitProcessor) Start a work queue on the elements in the provided collection, blocking until all work units have been completed.
-
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- TheExecutorService.interruptionChecker- the interruption checkernumParallelTasks- The number of parallel tasks.log- The log.workUnitProcessor- TheWorkQueue.WorkUnitProcessor.- Throws:
InterruptedException- If the work was interrupted.ExecutionException- If a worker throws an uncaught exception.
-
addWorkUnit
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
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
Completion barrier for work queue. This should be called after runWorkLoop() exits on the main thread (e.g. using try-with-resources).- Specified by:
closein interfaceAutoCloseable- Throws:
ExecutionException- If a worker threw an uncaught exception.
-