Source:
<code>private void warmUp(Map<Future<SingleBenchmarkRunner>, SingleBenchmarkRunner> futureMap, ConcurrentMap<SolverBenchmarkResult, Integer> singleBenchmarkResultIndexMap, long timePhaseEnd) { int tasksCount = futureMap.size(); for (int i = 0; i < tasksCount; i++) { Future<SingleBenchmarkRunner> future; try { future = warmUpExecutorCompletionService.take(); } catch (InterruptedException e) { singleBenchmarkRunnerExceptionLogger.error("Waiting for a warm up singleBenchmarkRunner was interrupted.", e); continue; } Throwable failureThrowable = null; SingleBenchmarkRunner singleBenchmarkRunner = futureMap.get(future); try { singleBenchmarkRunner = future.get(); } catch (InterruptedException e) { singleBenchmarkRunnerExceptionLogger.error("The warm up singleBenchmarkRunner ({}) was interrupted.", singleBenchmarkRunner, e); failureThrowable = e; } catch (ExecutionException e) { Throwable cause = e.getCause(); singleBenchmarkRunnerExceptionLogger.warn("The warm up singleBenchmarkRunner ({}) failed.", singleBenchmarkRunner, cause); failureThrowable = cause; } if (failureThrowable != null) { singleBenchmarkRunner.setFailureThrowable(failureThrowable); if (firstFailureSingleBenchmarkRunner == null) { firstFailureSingleBenchmarkRunner = singleBenchmarkRunner; } } SolverBenchmarkResult solverBenchmarkResult = singleBenchmarkRunner.getSingleBenchmarkResult().getSolverBenchmarkResult(); long timeLeftInCycle = timePhaseEnd - System.currentTimeMillis(); if (timeLeftInCycle > 0L) { warmUpPopulate(futureMap, singleBenchmarkResultIndexMap, new SolverBenchmarkResult[]{solverBenchmarkResult}, timeLeftInCycle); <START> tasksCount++; <END> } } }</code><technical_language>warmUpPopulate adds more 1 Future futureMap? tasksCounts++ accurate. I code more readable if for(i taskCounts) loop replaced a while (futureMap empty, pop one) Note: pop() is a method Queue. mimiced Map values().iterator().next(), a Queue is more natural here</technical_language>

Target:
private void warmUp(Map<Future<SingleBenchmarkRunner>, SingleBenchmarkRunner> futureMap, ConcurrentMap<SolverBenchmarkResult, Integer> singleBenchmarkResultIndexMap, long timePhaseEnd) { int tasksCount = futureMap.size(); for (int i = 0; i < tasksCount; i++) { Future<SingleBenchmarkRunner> future; try { future = warmUpExecutorCompletionService.take(); } catch (InterruptedException e) { throw new IllegalStateException("Waiting for a warm up singleBenchmarkRunner was interrupted.", e); } Throwable failureThrowable = null; SingleBenchmarkRunner singleBenchmarkRunner; try { singleBenchmarkRunner = future.get(); } catch (InterruptedException e) { singleBenchmarkRunner = futureMap.get(future); singleBenchmarkRunnerExceptionLogger.error("The warm up singleBenchmarkRunner ({}) was interrupted.", singleBenchmarkRunner, e); failureThrowable = e; } catch (ExecutionException e) { Throwable cause = e.getCause(); singleBenchmarkRunner = futureMap.get(future); singleBenchmarkRunnerExceptionLogger.warn("The warm up singleBenchmarkRunner ({}) failed.", singleBenchmarkRunner, cause); failureThrowable = cause; } if (failureThrowable != null) { singleBenchmarkRunner.setFailureThrowable(failureThrowable); if (firstFailureSingleBenchmarkRunner == null) { firstFailureSingleBenchmarkRunner = singleBenchmarkRunner; } } SolverBenchmarkResult solverBenchmarkResult = singleBenchmarkRunner.getSingleBenchmarkResult().getSolverBenchmarkResult(); long timeLeftInCycle = timePhaseEnd - System.currentTimeMillis(); if (timeLeftInCycle > 0L) { SolverBenchmarkResult[] solverBenchmarkResultSingleton = new SolverBenchmarkResult[]{solverBenchmarkResult}; warmUpPopulate(futureMap, singleBenchmarkResultIndexMap, solverBenchmarkResultSingleton, timeLeftInCycle); tasksCount++; } } }