Advertisement
nazar_art
Feb 2nd, 2025
16
0
Never
This is comment for paste Task for parallel processing
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Solution:
  2.  
  3. ExecutorService executor = Executors.newFixedThreadPool(3);
  4. CompletableFuture.allOf(
  5.         CompletableFuture.runAsync(() -> first.actions.stream()
  6.                 .sorted(Comparator.comparingInt(a -> a.priorityId))
  7. //                        .peek(a -> System.out.println("START: " + a.priorityId))
  8.                 .forEachOrdered(a -> processAction(first.entityId, a.priorityId, a.actionName)), executor),
  9.         CompletableFuture.runAsync(() -> second.actions.stream()
  10.                 .sorted(Comparator.comparingInt(o -> o.priorityId))
  11. //                        .peek(a -> System.out.println("START: " + a.priorityId))
  12.                 .forEachOrdered(a -> processAction(second.entityId, a.priorityId, a.actionName)), executor)
  13. );
  14. executor.shutdown();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement