Skip to main content

Practice ยท 2 of 2

Ordered results from unordered work

1. static List<Integer> fanout(List<Integer> inputs, Executor executor) โ€” for each input, supplyAsync(() -> input * 2, executor); after ALL complete (allOf + join), return the results IN SUBMISSION ORDER (join each future in list order). 2. static List<Integer> withFailures(List<Integer> inputs, Executor executor) โ€” same, but odd inputs THROW; recover per-branch with handle โ†’ -1 for failed branches; submission order preserved throughout. Use var f = CompletableFuture.supplyAsync(...) per input; never trust join order to equal completion order.

Difficulty: advanced

Back to lesson: Practice: Async drills