ParallelIndividualCompleter extends SequentialIndividualCompleter implements OptimizerStateListener { @Override public void complete(Iterable<? extends Individual> iterable) throws TerminationException { try { List<Future<Void>> returns = new ArrayList<>(); for (Individual individual : iterable) { if (individual.getState() != Individual.State.EVALUATED) { returns.add(executor.submit(new Complete(individual, control))); } } for (Future<Void> future : returns) { try { future.get(); } catch (InterruptedException e) { e.printStackTrace(); } } } catch (ExecutionException ex) { executor.shutdownNow(); if (ex.getCause() instanceof TerminationException) { throw (TerminationException) ex.getCause(); } throw new RuntimeException(ex); } } @Inject  ParallelIndividualCompleter(Control control, Decoder<Genotype, Object> decoder, Evaluator<Object> evaluator,
			@Constant(value = "maxThreads", namespace = ParallelIndividualCompleter.class) int maxThreads); @Override void complete(Iterable<? extends Individual> iterable); @Override void optimizationStarted(Optimizer optimizer); @Override void optimizationStopped(Optimizer optimizer);  }
@Test public void complete() throws TerminationException { IndividualCompleterModule module = new IndividualCompleterModule(); module.setThreads(4); module.setType(Type.PARALLEL); Injector injector = Guice.createInjector(new MockProblemModule(), module); IndividualFactory factory = injector.getInstance(IndividualFactory.class); Individual i1 = factory.create(); Individual i2 = factory.create(); ParallelIndividualCompleter completer = injector.getInstance(ParallelIndividualCompleter.class); completer.complete(i1, i2); Assert.assertTrue(i1.isEvaluated()); Assert.assertTrue(i2.isEvaluated()); completer.complete(i1); }