/** * Start the parallel decode. * * @throws Exception */ public void startDecode() throws Exception { final List<RowProvider> rowProviders = getRowProviders(); remainingTasks = rowProviders.size(); for (final RowProvider rowProvider : rowProviders) { threadPool.submit(new DecodeTask<>(rowProvider, this)); } }
private void offerResult(final Object result) throws InterruptedException { while (!shouldTerminate() && !parent.results.offer(result)) { // Results buffer is full, wait until there is some space Thread.sleep(1); } }
@Override public void run() { try { rowProvider.init(); final Iterator<T> transformed = parent.rowTransformer.apply(rowProvider); while (transformed.hasNext() && !shouldTerminate()) { offerResult(transformed.next()); } // No more rows, signal the end of this task. offerResult(TASK_END_MARKER); } catch (final Exception e) { // Don't overwrite the original exception if there is one if (!parent.hasException()) { parent.setDecodeException(e); } } finally { try { rowProvider.close(); } catch (final IOException e) { // Ignore } } } }