ForkJoinPool with java 8

https://www.youtube.com/watch?v=w0Fd5PfI8TQ

if (false) {
                ForkJoinPool customPool = new ForkJoinPool(4);

                List<Integer> list = Arrays.asList(1, 2, 3, 4);

                // map(). filter() good
                // sort(), distinct() not so good

                ForkJoinTask<Integer> hackTask = customPool.submit(() -> {
                    return list.parallelStream()
                            .peek(w -> workers.add(Thread.currentThread().getName()))
                            .filter(w -> w.getColor() == RED)
                            .mapToInt(w -> getWeight())
                            .sum();
                });

                int sum = hackTask.get();

            }

No comments:

Post a Comment