Source:
public Map<FingerprintIdDetails, Fingerprint> fingerprintFiles(final Collection<Path> files, final int threads, final int waitTime, final TimeUnit waitTimeUnit) { final AtomicInteger filesRead = new AtomicInteger(0); final ExecutorService executor = new ThreadPoolExecutorWithExceptions(threads); final ExecutorCompletionService<Path> executorCompletionService = new ExecutorCompletionService<>(executor); final IntervalList intervals = this.haplotypes.getIntervalList(); final Map<FingerprintIdDetails, Fingerprint> retval = new ConcurrentHashMap<>(files.size()); for (final Path p : files) { executorCompletionService.submit(() -> { final Map<FingerprintIdDetails, Fingerprint> oneFileFingerprints; if (CheckFingerprint.fileContainsReads(p)) { oneFileFingerprints = fingerprintSamFile(p, intervals); } else { oneFileFingerprints = fingerprintVcf(p); } if (oneFileFingerprints.isEmpty()) { log.warn("No fingerprint data was found in file:" + p); } else { retval.putAll(oneFileFingerprints); } log.debug("Processed file: " + p.toUri().toString() + " (" + filesRead.get() + ")"); if (filesRead.incrementAndGet() % 100 == 0) { log.info("Processed " + filesRead.get() + " out of " + files.size()); } }, p); } executor.shutdown(); try { executor.awaitTermination(waitTime, waitTimeUnit); } catch (final InterruptedException ie) { throw new PicardException("Interrupted while waiting for executor to terminate.", ie); } for (int i = 0; i < files.size(); i++) { try { executorCompletionService.take().get(); } catch (InterruptedException | ExecutionException e) { throw new PicardException("Failed to fingerprint", e); } } log.info("Processed files. " + retval.size() + " fingerprints found in map."); return retval; }

Target:
public Map<FingerprintIdDetails, Fingerprint> fingerprintFiles(final Collection<Path> files, final int threads, final int waitTime, final TimeUnit waitTimeUnit) { final AtomicInteger filesRead = new AtomicInteger(0); final ExecutorService executor = new ThreadPoolExecutorWithExceptions(threads); final ExecutorCompletionService<Path> executorCompletionService = new ExecutorCompletionService<>(executor); final IntervalList intervals = this.haplotypes.getIntervalList(); final Map<FingerprintIdDetails, Fingerprint> retval = new ConcurrentHashMap<>(files.size()); for (final Path p : files) { executorCompletionService.submit(() -> { final Map<FingerprintIdDetails, Fingerprint> oneFileFingerprints; if (CheckFingerprint.fileContainsReads(p)) { oneFileFingerprints = fingerprintSamFile(p, intervals); } else { oneFileFingerprints = fingerprintVcf(p); } if (oneFileFingerprints.isEmpty()) { log.warn("No fingerprint data was found in file:" + p); } retval.putAll(oneFileFingerprints); log.debug("Processed file: " + p.toUri().toString() + " (" + filesRead.get() + ")"); if (filesRead.incrementAndGet() % 100 == 0) { log.info("Processed " + filesRead.get() + " out of " + files.size()); } }, p); } executor.shutdown(); try { executor.awaitTermination(waitTime, waitTimeUnit); } catch (final InterruptedException ie) { throw new PicardException("Interrupted while waiting for executor to terminate.", ie); } for (int i = 0; i < files.size(); i++) { try { executorCompletionService.take().get(); } catch (InterruptedException | ExecutionException e) { throw new PicardException("Failed to fingerprint", e); } } log.info("Processed files. " + retval.size() + " fingerprints found in map."); return retval; }