LazyExecutorService implements ExecutorService { @CanIgnoreReturnValue @Override public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException { List<Future<T>> result = Lists.newLinkedList(); try { for (Callable<T> task : tasks) { result.add(submit(task)); } List<Callable<Void>> monitorTasks = createMonitorTasksFor(result, 0, null); backingService.invokeAll(monitorTasks); } finally { for (Future<T> future : result) { future.cancel(true); } } return result; } LazyExecutorService();  LazyExecutorService(ExecutorService backingService); @Override void shutdown(); @CanIgnoreReturnValue @Override List<Runnable> shutdownNow(); @Override boolean isShutdown(); @Override boolean isTerminated(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override Future<T> submit(final Callable<T> task); @Override Future<T> submit(Runnable task, T result); @Override Future<?> submit(Runnable command); @CanIgnoreReturnValue @Override List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks); @CanIgnoreReturnValue @Override List<Future<T>> invokeAll(
      Collection<? extends Callable<T>> tasks, final long timeout, final TimeUnit unit); @Override T invokeAny(Collection<? extends Callable<T>> tasks); @Override T invokeAny(
      final Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit); @Override void execute(Runnable command);  }
@Test public void testInvokeAllSubmitAllTasks() throws Exception { List<Callable<Void>> tasks = ImmutableList.of(() -> null, () -> null); List<Future<Void>> futures = lazyExecutorService.invokeAll(tasks); assertThat(futures).hasSize(2); }
@Test public void testInvokeAllSubmitAllTasksWithTimeout() throws Exception { List<Callable<Void>> tasks = ImmutableList.of(() -> null, () -> null); List<Future<Void>> futures = lazyExecutorService.invokeAll(tasks, 1, TimeUnit.MILLISECONDS); assertThat(futures).hasSize(2); }