public class ExecutorServiceResultsHandler<V> extends Object implements Iterable<V>
Callables, get results via iteration,
and handle failure quickly. When a submitted callable throws an exception in its thread this
will result in a RuntimeException when iterating over results. Typical usage is as follows:
if (Thread.currentThread().isInterrupted()) {
throw new RuntimeException("The thread was interrupted, likely indicating failure in a sibling thread.");
}submit() method.finishedSubmitting().ExecutorService.shutdownNow() will be called resulting in all still running callables being interrupted,
and a RuntimeException will be thrown
You can also call abort() to shut down the threads yourself.
| Constructor and Description |
|---|
ExecutorServiceResultsHandler(ExecutorService executorService) |
| Modifier and Type | Method and Description |
|---|---|
void |
abort() |
void |
awaitCompletion()
Convenience method to wait for the callables to finish for when you don't care about the results.
|
void |
finishedSubmitting() |
Iterator<V> |
iterator() |
void |
submit(Callable<V> task) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic ExecutorServiceResultsHandler(ExecutorService executorService)
Copyright © 2020. All rights reserved.