Guest User

Untitled

a guest
Feb 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. public class CompletableFutureTests {
  2.  
  3. public static final int END_EXCLUSIVE = 1000000;
  4. public static final Random random = new Random();
  5.  
  6. @Test
  7. public void __1() throws ExecutionException, InterruptedException {
  8.  
  9. final long d = System.currentTimeMillis();
  10.  
  11. final Optional<CompletableFuture<BigDecimal>> reduce = IntStream
  12. .range(0, END_EXCLUSIVE)
  13. .mapToObj((t) -> supplyAsync(() -> new BigDecimal(random.nextInt())))
  14. .parallel()
  15. .reduce((left, right) -> left.thenCombine(right, (l, r) -> l.add(r)));
  16.  
  17. final BigDecimal x = reduce.get().get();
  18. final long l1 = System.currentTimeMillis();
  19. System.out.println(x);
  20. System.out.println(l1 - d);
  21. }
  22.  
  23. @Test
  24. public void __2() throws ExecutionException, InterruptedException {
  25.  
  26. final long d = System.currentTimeMillis();
  27.  
  28. final Optional<CompletableFuture<Stream<Integer>>> reduce = IntStream
  29. .range(0, END_EXCLUSIVE)
  30. .mapToObj((t) -> supplyAsync(() -> ...))
  31. .parallel()
  32. .reduce((left, right) -> left.thenCombine(right, (l, r) -> ... ));
  33.  
  34.  
  35. final List<Integer> collect = reduce.get().get().collect(Collectors.toList());
  36.  
  37. System.out.println(collect.size());
  38.  
  39. }
  40. }
Add Comment
Please, Sign In to add comment