| Modifier and Type | Class and Description |
|---|---|
| public static interface | |
| private static class | WorkQueue.
the generic type T>A wrapper for work units (needed to send a poison pill as a null value, since BlockingQueue does not accept null values). |
| Modifier and Type | Field and Description |
|---|---|
| private final InterruptionChecker | interruptionChecker
The shared InterruptionChecker, used to detect thread interruption and execution exceptions, and to shut down all threads if either of these occurs. |
| private final LogNode | log
The log node. |
| private final AtomicInteger | numIncompleteWorkUnits
The number of work units remaining to be processed, plus the number of currently running threads working on a work unit. |
| private final int | numWorkers
The number of workers. |
| private final ConcurrentLinkedQueue | workerFutures
The Future object added for each worker, used to detect worker completion. |
| private final WorkQueue. | workUnitProcessor
The work unit processor. |
| private final BlockingQueue | workUnits
The queue of work units. |
| Access | Constructor and Description |
|---|---|
| private | WorkQueue(final Collection<T>
the initial work units initialWorkUnits, final WorkQueue.the work unit processor workUnitProcessor,the number of workers numWorkers, final InterruptionChecker the interruption checker interruptionChecker, final LogNode the log log)A parallel work queue. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | addWorkUnits(final Collection<T>
The work units to add to the tail of the queue. workUnits)Add multiple units of work. |
| public void | |
| private void | |
| public static < The type of the work queue units. U> void | runWorkQueue(final Collection<U>
The work queue units to process. elements, final ExecutorService The executorService, final InterruptionChecker ExecutorService.the interruption checker interruptionChecker, final int The number of parallel tasks. numParallelTasks, final LogNode The log. log, final WorkQueue.The workUnitProcessorWorkUnitProcessor.Start a work queue on the elements in the provided collection, blocking until all work units have been completed. |
| private void | |
| private void | startWorkers(final ExecutorService
the executor service executorService, final int the number of worker tasks to start numTasks)Start worker threads with a shared log. |
| interruptionChecker | back to summary |
|---|---|
| private final InterruptionChecker interruptionChecker The shared InterruptionChecker, used to detect thread interruption and execution exceptions, and to shut down all threads if either of these occurs. | |
| log | back to summary |
|---|---|
| private final LogNode log The log node. | |
| numIncompleteWorkUnits | back to summary |
|---|---|
| private final AtomicInteger numIncompleteWorkUnits The number of work units remaining to be processed, plus the number of currently running threads working on a work unit. | |
| numWorkers | back to summary |
|---|---|
| private final int numWorkers The number of workers. | |
| workerFutures | back to summary |
|---|---|
| private final ConcurrentLinkedQueue<Future<?>> workerFutures The Future object added for each worker, used to detect worker completion. | |
| workUnitProcessor | back to summary |
|---|---|
| private final WorkQueue. The work unit processor. | |
| workUnits | back to summary |
|---|---|
| private final BlockingQueue<WorkQueue. The queue of work units. | |
| WorkQueue | back to summary |
|---|---|
| private WorkQueue(final Collection<T> initialWorkUnits, final WorkQueue. A parallel work queue.
| |
| addWorkUnit | back to summary |
|---|---|
| public void addWorkUnit(final T workUnit) Add a unit of work. May be called by workers to add more work units to the tail of the queue.
| |
| addWorkUnits | back to summary |
|---|---|
| public void addWorkUnits(final Collection<T> workUnits) Add multiple units of work. May be called by workers to add more work units to the tail of the queue.
| |
| close | back to summary |
|---|---|
| public void close() throws ExecutionException Implements java. Completion barrier for work queue. This should be called after runWorkLoop() exits on the main thread (e.g. using try-with-resources).
| |
| runWorkLoop | back to summary |
|---|---|
| private void runWorkLoop() throws InterruptedException, ExecutionException Start a worker. Called by startWorkers(), but should also be called by the main thread to do some of the work on that thread, to prevent deadlock in the case that the ExecutorService doesn't have as many threads available as numParallelTasks. When this method returns, either all the work has been completed, or this or some other thread was interrupted. If InterruptedException is thrown, this thread or another was interrupted.
| |
| runWorkQueue | back to summary |
|---|---|
| public static <U> void runWorkQueue(final Collection<U> elements, final ExecutorService executorService, final InterruptionChecker interruptionChecker, final int numParallelTasks, final LogNode log, final WorkQueue. Start a work queue on the elements in the provided collection, blocking until all work units have been completed.
| |
| sendPoisonPills | back to summary |
|---|---|
| private void sendPoisonPills() Send poison pills to workers.
| |
| startWorkers | back to summary |
|---|---|
| private void startWorkers(final ExecutorService executorService, final int numTasks) Start worker threads with a shared log.
| |
| Modifier and Type | Method and Description |
|---|---|
| public void | processWorkUnit(T
The work unit. workUnit, WorkQueue<T> The work queue. workQueue, LogNode The log. log)Process a work unit. |
| processWorkUnit | back to summary |
|---|---|
| public void processWorkUnit(T workUnit, WorkQueue<T> workQueue, LogNode log) throws InterruptedException Process a work unit.
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final T | workUnit
The work unit. |
| Access | Constructor and Description |
|---|---|
| public |
| workUnit | back to summary |
|---|---|
| pack-priv final T workUnit The work unit. | |
| WorkUnitWrapper | back to summary |
|---|---|
| public WorkUnitWrapper(final T workUnit) Constructor.
| |