Source:
public void invalidateRepositories(Collection<? extends RepositoryInfo> repos) { if (repos == null || repos.isEmpty()) { repositories.clear(); } else { Map<String, Repository> newrepos = Collections.synchronizedMap(new HashMap<>(repos.size())); Statistics elapsed = new Statistics(); boolean verbose = RuntimeEnvironment.getInstance().isVerbose(); if (verbose) { LOGGER.log(Level.FINE, "invalidating " + repos.size() + " repositories"); } final CountDownLatch latch = new CountDownLatch(repos.size()); final ExecutorService executor = Executors.newFixedThreadPool( Runtime.getRuntime().availableProcessors(), new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread thread = Executors.defaultThreadFactory().newThread(runnable); thread.setName("invalidate-repos-" + thread.getId()); return thread; } }); for (RepositoryInfo i : repos) { executor.submit(new Runnable() { @Override public void run() { try { Repository r = RepositoryFactory.getRepository(i); if (r == null) { LOGGER.log(Level.WARNING, "Failed to instantiate internal repository data for {0} in {1}", new Object[]{i.getType(), i.getDirectoryName()}); } else { newrepos.put(r.getDirectoryName(), r); } } catch (Exception ex) { LOGGER.log(Level.WARNING, "Could not create " + i.getType() + " for '" + i.getDirectoryName(), ex); } finally { latch.countDown(); } } }); } try { latch.await(); } catch (InterruptedException ex) { LOGGER.log(Level.SEVERE, "latch exception{0}", ex); } executor.shutdown(); repositories = newrepos; if (verbose) { elapsed.report(LOGGER, "done invalidating repositories"); } } }

Target:
public void invalidateRepositories(Collection<? extends RepositoryInfo> repos) { if (repos == null || repos.isEmpty()) { repositories.clear(); } else { Map<String, Repository> newrepos = Collections.synchronizedMap(new HashMap<>(repos.size())); Statistics elapsed = new Statistics(); boolean verbose = RuntimeEnvironment.getInstance().isVerbose(); if (verbose) { LOGGER.log(Level.FINE, "invalidating {0} repositories", repos.size()); } final CountDownLatch latch = new CountDownLatch(repos.size()); final ExecutorService executor = Executors.newFixedThreadPool( Runtime.getRuntime().availableProcessors(), new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread thread = Executors.defaultThreadFactory().newThread(runnable); thread.setName("invalidate-repos-" + thread.getId()); return thread; } }); for (RepositoryInfo i : repos) { executor.submit(new Runnable() { @Override public void run() { try { Repository r = RepositoryFactory.getRepository(i); if (r == null) { LOGGER.log(Level.WARNING, "Failed to instantiate internal repository data for {0} in {1}", new Object[]{i.getType(), i.getDirectoryName()}); } else { newrepos.put(r.getDirectoryName(), r); } } catch (Exception ex) { LOGGER.log(Level.WARNING, "Could not create " + i.getType() + " for '" + i.getDirectoryName(), ex); } finally { latch.countDown(); } } }); } try { latch.await(); } catch (InterruptedException ex) { LOGGER.log(Level.SEVERE, "latch exception{0}", ex); } executor.shutdown(); repositories.clear(); repositories.putAll(newrepos); if (verbose) { elapsed.report(LOGGER, "done invalidating repositories"); } } }