Package com.opencsv.bean.concurrent
Class AccumulateCsvResults<T>
java.lang.Object
java.lang.Thread
com.opencsv.bean.concurrent.AccumulateCsvResults<T>
- Type Parameters:
T
- Type of output being created (bean or strings)
- All Implemented Interfaces:
Runnable
The accumulator takes two queues of results of transforming text input
into bean output or bean input into text output (output and exceptions)
and orders them for later consumption.
This task is delegated to a separate thread so threads can quickly queue
their results in a (synchronized, thread-safe) queue and move on with other
work, while the relatively expensive operation of ordering the results
doesn't block other threads waiting for access to the ordered map.
- Since:
- 4.0
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private final ConcurrentMap
<Long, T> private final BlockingQueue
<OrderedObject<T>> private final org.apache.commons.collections4.ListValuedMap
<Long, CsvException> All access to this variable must be synchronized.private final BlockingQueue
<OrderedObject<CsvException>> Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorsConstructorDescriptionAccumulateCsvResults
(BlockingQueue<OrderedObject<T>> resultantBeansQueue, BlockingQueue<OrderedObject<CsvException>> thrownExceptionsQueue, SortedSet<Long> expectedRecords, ConcurrentMap<Long, T> resultantBeanMap, org.apache.commons.collections4.ListValuedMap<Long, CsvException> thrownExceptionsMap) The only accepted constructor for the accumulator. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
Checks whether the accumulator should shut itself down.void
run()
(package private) void
setMustStop
(boolean mustStop) Tells the accumulator whether it should stop.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
resultantBeansQueue
-
thrownExceptionsQueue
-
expectedRecords
-
resultantBeanMap
-
mustStop
private boolean mustStop -
thrownExceptionsMap
All access to this variable must be synchronized.
-
-
Constructor Details
-
AccumulateCsvResults
AccumulateCsvResults(BlockingQueue<OrderedObject<T>> resultantBeansQueue, BlockingQueue<OrderedObject<CsvException>> thrownExceptionsQueue, SortedSet<Long> expectedRecords, ConcurrentMap<Long, T> resultantBeanMap, org.apache.commons.collections4.ListValuedMap<Long, CsvException> thrownExceptionsMap) The only accepted constructor for the accumulator.- Parameters:
resultantBeansQueue
- A queue of beans coming out of the pool of threads creating them. The accumulator pulls from this queue.thrownExceptionsQueue
- A queue ofCsvException
and its derivatives coming out of the pool of threads creating beans. The accumulator pulls from this queue.expectedRecords
- A list of outstanding record numbers so gaps in ordering due to filtered input or exceptions while converting can be detected.resultantBeanMap
- The (ordered) map of beans that have been created. The accumulator inserts into this map.thrownExceptionsMap
- The map of suppressed exceptions thrown during bean creation. The accumulator inserts into this map. All access to this variable must be synchronized.
-
-
Method Details
-
isMustStop
private boolean isMustStop()Checks whether the accumulator should shut itself down. This method must always be used to check the value of the signal boolean, because it's synchronized.- Returns:
- Whether the accumulator should stop
-
setMustStop
void setMustStop(boolean mustStop) Tells the accumulator whether it should stop. This method must always be used to set the value of the signal boolean, because it's synchronized.- Parameters:
mustStop
- Whether the accumulator should stop
-
run
public void run()
-