I want to run the threads in parallel and handle the exception if any thread fails while running. But, when I am using the future.get method, I am unable to maintain parallel execution. How can this be resolved?
for (int i = 0; i < threads; i++) {
final Future<Void> future = executor.submit(new ReaderDirectWithPartition_JDBC(outputPath + i, partitionedQuery, propparameters, props));
try {
future.get();
} catch (final CancellationException ce) {
log.error(ce.getMessage());
executor.shutdownNow();
} catch (final ExecutionException ee) {
log.error(ee.getMessage());
executor.shutdownNow();
} catch (final InterruptedException ie) {
Thread.currentThread().interrupt(); // ignore/reset
log.error(ie.getMessage());
executor.shutdownNow();
}
}