Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CompletableFutureTests {
- public static final int END_EXCLUSIVE = 1000000;
- public static final Random random = new Random();
- @Test
- public void __1() throws ExecutionException, InterruptedException {
- final long d = System.currentTimeMillis();
- final Optional<CompletableFuture<BigDecimal>> reduce = IntStream
- .range(0, END_EXCLUSIVE)
- .mapToObj((t) -> supplyAsync(() -> new BigDecimal(random.nextInt())))
- .parallel()
- .reduce((left, right) -> left.thenCombine(right, (l, r) -> l.add(r)));
- final BigDecimal x = reduce.get().get();
- final long l1 = System.currentTimeMillis();
- System.out.println(x);
- System.out.println(l1 - d);
- }
- @Test
- public void __2() throws ExecutionException, InterruptedException {
- final long d = System.currentTimeMillis();
- final Optional<CompletableFuture<Stream<Integer>>> reduce = IntStream
- .range(0, END_EXCLUSIVE)
- .mapToObj((t) -> supplyAsync(() -> ...))
- .parallel()
- .reduce((left, right) -> left.thenCombine(right, (l, r) -> ... ));
- final List<Integer> collect = reduce.get().get().collect(Collectors.toList());
- System.out.println(collect.size());
- }
- }
Add Comment
Please, Sign In to add comment