This is the historically established precedent for dealing with input errors
in opencsv. This implementation expects all uncaught exceptions from its
threads to be wrapped in a java.. The number of
threads in the pool is fixed.
It is not intended for this executor to be instantiated and receive jobs directly. There are function-specific derived classes for that purpose.
This executor adds significant logic to the basic idea of an
java., and thus must be used differently
from other executors. Usage follows this pattern:
prepare()complete()java.util.stream.Stream out of
the executor itself. This is most easily done with
java.util.stream.StreamSupport#stream(Spliterator, boolean) getCapturedExceptions()The execution structure of this class is:
The threads in the executor queue their results in a thread-safe queue, which should be O(1), minimizing wait time due to synchronization. The accumulator then removes items from the queue and inserts them into a sorted data structure, which is O(log n) on average and O(n) in the worst case. If the user has told us she doesn't need sorted data, the accumulator is not necessary, and thus is not started.
| Modifier and Type | Field and Description |
|---|---|
| protected AccumulateCsvResults | accumulateThread
A separate thread that accumulates and orders results. |
| protected final Locale | errorLocale
The locale for error messages. |
| protected final SortedSet | expectedRecords
A list of the ordinals of data records still to be expected by the accumulator. |
| private final boolean | orderedResults
Determines whether resulting data sets have to be in the same order as the input. |
| private ConcurrentNavigableMap | resultantBeansMap
A sorted, concurrent map for the beans created. |
| protected final BlockingQueue | resultQueue
A queue of the beans created. |
| private Throwable | terminalException
The exception that caused this Executor to stop executing. |
| private ListValuedMap | thrownExceptionsMap
A multi-valued map for any exceptions captured. |
| protected final BlockingQueue | thrownExceptionsQueue
A queue of exceptions thrown by threads during processing. |
| Access | Constructor and Description |
|---|---|
| pack-priv | IntolerantThreadPoolExecutor(boolean
Whether order should be preserved in the results orderedResults, Locale The errorLocale to use for error messages. errorLocale)Constructor for a thread pool executor that stops by itself as soon as any thread throws an exception. |
| Modifier and Type | Method and Description |
|---|---|
| protected void | afterExecute(Runnable r, Throwable t)
Overrides java. Shuts the Executor down if the thread ended in an exception. |
| private boolean | Returns: false if conversion is complete and no more results
can ever be expected out of this Spliterator, true
otherwise. If true is returned, it is guaranteed that at
least one result is available immediately to the caller.Determines whether more conversion results can be expected. |
| public int | characteristics()
Implements java. Returns a set of characteristics of this Spliterator and its elements. |
| protected void | |
| public void | |
| public long | estimateSize()
Implements java. Returns an estimate of the number of elements that would be
encountered by a |
| public List | Returns: All exceptions capturedReturns exceptions captured during the conversion process if the conversion process was set not to propagate these errors up the call stack. |
| public Throwable | Returns: The exception that halted one of the threads, which caused the executor to shut itself downIf an unrecoverable exception was thrown during processing, it can be retrieved here. |
| private boolean | |
| public void | |
| public List | shutdownNow()
Overrides java. Implements java. Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution. |
| public boolean | tryAdvance(Consumer<? super T> action)
Implements java. If a remaining element exists: performs the given action on it,
returning |
| public Spliterator | trySplit()
Implements java. If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator. |
| accumulateThread | back to summary |
|---|---|
| protected AccumulateCsvResults<T> accumulateThread A separate thread that accumulates and orders results. | |
| errorLocale | back to summary |
|---|---|
| protected final Locale errorLocale The locale for error messages. | |
| expectedRecords | back to summary |
|---|---|
| protected final SortedSet<Long> expectedRecords A list of the ordinals of data records still to be expected by the accumulator. | |
| orderedResults | back to summary |
|---|---|
| private final boolean orderedResults Determines whether resulting data sets have to be in the same order as the input. | |
| resultantBeansMap | back to summary |
|---|---|
| private ConcurrentNavigableMap<Long, T> resultantBeansMap A sorted, concurrent map for the beans created. | |
| resultQueue | back to summary |
|---|---|
| protected final BlockingQueue<OrderedObject<T>> resultQueue A queue of the beans created. | |
| terminalException | back to summary |
|---|---|
| private Throwable terminalException The exception that caused this Executor to stop executing. | |
| thrownExceptionsMap | back to summary |
|---|---|
| private ListValuedMap<Long, CsvException> thrownExceptionsMap A multi-valued map for any exceptions captured. The multi-valued part is important because the same line can throw more than one exception. All access to this variable must be synchronized. | |
| thrownExceptionsQueue | back to summary |
|---|---|
| protected final BlockingQueue<OrderedObject<CsvException>> thrownExceptionsQueue A queue of exceptions thrown by threads during processing. | |
| IntolerantThreadPoolExecutor | back to summary |
|---|---|
| pack-priv IntolerantThreadPoolExecutor(boolean orderedResults, Locale errorLocale) Constructor for a thread pool executor that stops by itself as soon as any thread throws an exception. Threads never time out and the queue for inbound work is unbounded.
| |
| afterExecute | back to summary |
|---|---|
| protected void afterExecute(Runnable r, Throwable t) Overrides java. Shuts the Executor down if the thread ended in an exception.
| |
| areMoreResultsAvailable | back to summary |
|---|---|
| private boolean areMoreResultsAvailable() Determines whether more conversion results can be expected.
Since
| |
| characteristics | back to summary |
|---|---|
| public int characteristics() Implements java. Doc from java. Returns a set of characteristics of this Spliterator and its
elements. The result is represented as ORed values from If a Spliterator reports an inconsistent set of characteristics (either those returned from a single invocation or across multiple invocations), no guarantees can be made about any computation using this Spliterator.
| |
| checkExceptions | back to summary |
|---|---|
| protected void checkExceptions() Checks whether exceptions are available that should halt processing. This is the case with unrecoverable errors, such as parsing the input, or if exceptions in conversion should be thrown by request of the user. | |
| complete | back to summary |
|---|---|
| public void complete() throws InterruptedException Sends a signal to the Executor that it should shut down once all threads have completed.
| |
| estimateSize | back to summary |
|---|---|
| public long estimateSize() Implements java. Doc from java. Returns an estimate of the number of elements that would be
encountered by a If this Spliterator is
| |
| getCapturedExceptions | back to summary |
|---|---|
| public List Returns exceptions captured during the conversion process if the conversion process was set not to propagate these errors up the call stack. The call is nondestructive.
| |
| getTerminalException | back to summary |
|---|---|
| public Throwable getTerminalException() If an unrecoverable exception was thrown during processing, it can be retrieved here.
| |
| isConversionComplete | back to summary |
|---|---|
| private boolean isConversionComplete() | |
| prepare | back to summary |
|---|---|
| public void prepare() Prepares this Executor to receive jobs. | |
| shutdownNow | back to summary |
|---|---|
| public List Overrides java. Implements java. Doc from java. Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution. These tasks are drained (removed) from the task queue upon return from this method. This method does not wait for actively executing tasks to
terminate. Use There are no guarantees beyond best-effort attempts to stop
processing actively executing tasks. This implementation
interrupts tasks via
| |
| tryAdvance | back to summary |
|---|---|
| public boolean tryAdvance(Consumer<? super T> action) Implements java. Doc from java. If a remaining element exists: performs the given action on it,
returning Subsequent behavior of a spliterator is unspecified if the action throws an exception.
| |
| trySplit | back to summary |
|---|---|
| public Spliterator Implements java. Doc from java. If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator. If this Spliterator is Unless this Spliterator covers an infinite number of elements,
repeated calls to
This method may return
| |