MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

concurrent/CachedThreadPool3.java:18–33  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

16 }
17 }
18 public static void main(String[] args)
19 throws InterruptedException {
20 ExecutorService exec =
21 Executors.newCachedThreadPool();
22 List<CountingTask> tasks =
23 IntStream.range(0, 10)
24 .mapToObj(CountingTask::new)
25 .collect(Collectors.toList());
26 List<Future<Integer>> futures =
27 exec.invokeAll(tasks);
28 Integer sum = futures.stream()
29 .map(CachedThreadPool3::extractResult)
30 .reduce(0, Integer::sum);
31 System.out.println("sum = " + sum);
32 exec.shutdown();
33 }
34}
35/* Output:
360 pool-1-thread-1 100

Callers

nothing calls this directly

Calls 2

rangeMethod · 0.80
streamMethod · 0.45

Tested by

no test coverage detected