final ExecutorService service = Executors.newFixedThreadPool(context
.getResults().size());
final List<Future<CheckUrlsProcess>> tasks = new ArrayList<Future<CheckUrlsProcess>>();
while (iter.hasNext()) {
fireEvent(new BasicChainEvent(this, context, EventTypes.FORK));
final CheckUrlsProcess process = new CheckUrlsProcess(client,
localContext, iter.next());
final Future<CheckUrlsProcess> future = service.submit(process,
process);
tasks.add(future);
}
try {
for (final Future<CheckUrlsProcess> f : tasks) {
final Result result = f.get().getResult();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(result.getResult() + " for " + result.getURI()
+ " with " + result.getUserData());
}
}
service.shutdown();
} catch (final InterruptedException e) {
LOGGER.error(e);
fireEvent(new BasicChainEvent(this, context, EventTypes.EXCEPTION));
} catch (final ExecutionException e) {
LOGGER.error(e);
fireEvent(new BasicChainEvent(this, context, EventTypes.EXCEPTION));
} finally {
try {
if (!service.isShutdown()) {
service.awaitTermination(terminationTime, TimeUnit.SECONDS);
}
} catch (final InterruptedException e) {
LOGGER.error(e);
fireEvent(new BasicChainEvent(this, context,
EventTypes.EXCEPTION));
} finally {
if (!service.isShutdown()) {
service.shutdownNow();
}