public void run(DocWrapper docWrapper, final String currProcess, final EntityRow rows) throws Exception { entityInitialized = false; this.docWrapper = docWrapper; this.currentProcess = currProcess; entityEnded.set(false); try { if (entityProcessorWrapper.size() <= 1) { runAThread(entityProcessorWrapper.get(0), rows, currProcess); } else { final CountDownLatch latch = new CountDownLatch(entityProcessorWrapper.size()); for (final ThreadedEntityProcessorWrapper processorWrapper : entityProcessorWrapper) { Runnable runnable = new Runnable() { public void run() { try { runAThread(processorWrapper, rows, currProcess); } catch (Exception e) { entityEnded.set(true); exception = e; } finally { latch.countDown(); } } }; executorSvc.execute(runnable); } try { latch.await(); } catch (InterruptedException e) { // TODO } Exception copy = exception; if (copy != null) { exception = null; throw copy; } } } finally { entityProcessor.destroy(); } }