public static < U > void runWorkQueue ( final Collection < U > elements , final ExecutorService executorService , final InterruptionChecker interruptionChecker , final int numParallelTasks , final LogNode log , final WorkUnitProcessor < U > workUnitProcessor ) throws InterruptedException , ExecutionException { if ( elements . isEmpty ( ) ) { // Nothing to do return ; } // WorkQueue#close() is called when this try-with-resources block terminates, initiating a barrier wait // while all worker threads complete. try ( WorkQueue < U > workQueue = new WorkQueue <> ( elements , workUnitProcessor , numParallelTasks , interruptionChecker , log ) ) { // Start (numParallelTasks - 1) worker threads (may start zero threads if numParallelTasks == 1) workQueue . startWorkers ( executorService , numParallelTasks - 1 ) ; // Use the current thread to do work too, in case there is only one thread available in the // ExecutorService, or in case numParallelTasks is greater than the number of available threads in the // ExecutorService. workQueue . runWorkLoop ( ) ; } }
Start a work queue on the elements in the provided collection blocking until all work units have been completed .