Skip to content

Instantly share code, notes, and snippets.

@muhdkhokhar
Created October 23, 2024 19:07
Show Gist options
  • Save muhdkhokhar/1bf07487442f6a2c57550eec851b9fec to your computer and use it in GitHub Desktop.
Save muhdkhokhar/1bf07487442f6a2c57550eec851b9fec to your computer and use it in GitHub Desktop.
public static void main(String[] args) throws InterruptedException, ExecutionException {
List<Integer> list1 = List.of(1, 2, 3);
List<Integer> list2 = List.of(4, 5, 6);
List<Integer> list3 = List.of(7, 8, 9);
CompletableFuture<Void> future1 = CompletableFuture.runAsync(() -> processList1(list1));
CompletableFuture<Void> future2 = CompletableFuture.runAsync(() -> processList2(list2));
CompletableFuture<Void> future3 = CompletableFuture.runAsync(() -> processList3(list3));
// Wait for all futures to complete
CompletableFuture.allOf(future1, future2, future3).join();
System.out.println("All lists processed.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment