AsyncService { @Async public CompletableFuture<List<String>> completableFutureTask(String start) { logger.warn(Thread.currentThread().getName() + "start this task!"); List<String> results = movies.stream().filter(movie -> movie.startsWith(start)).collect(Collectors.toList()); try { Thread.sleep(1000L); } catch (InterruptedException e) { e.printStackTrace(); } return CompletableFuture.completedFuture(results); }  @Async CompletableFuture<List<String>> completableFutureTask(String start);  }
@Test public void testCompletableFutureTask() throws InterruptedException, ExecutionException { long start = System.currentTimeMillis(); List<String> words = Arrays.asList("F", "T", "S", "Z", "J", "C"); List<CompletableFuture<List<String>>> completableFutureList = words.stream() .map(word -> asyncService.completableFutureTask(word)) .collect(Collectors.toList()); List<List<String>> results = completableFutureList.stream().map(CompletableFuture::join).collect(Collectors.toList()); System.out.println("Elapsed time: " + (System.currentTimeMillis() - start)); System.out.println(results.toString()); }