Custom Thread Pools In Java 8 Parallel Streams (#1088)

* String to char array and char array to String.

* Method change

* Custom ThreadPool In Java 8 Parallel Streams

* Implemented suggested edits from editor.

* Broke long method signature

* Changed primitive type int to long and formula.

* Update wrapper type to Long
This commit is contained in:
Dotun Kola-Olaleye 2017-02-02 18:30:05 +01:00 committed by adamd1985
parent c350e8b423
commit a1312e9ce0
1 changed files with 4 additions and 4 deletions

View File

@ -1,5 +1,5 @@
package org.baeldung.java.streams;
import org.junit.Test;
import java.util.ArrayList;
@ -17,18 +17,18 @@ public class ThreadPoolInParallelStream {
@Test
public void giveRangeOfLongs_whenSummedInParallel_shouldBeEqualToExpectedTotal()
throws InterruptedException, ExecutionException {
throws InterruptedException, ExecutionException {
long firstNum = 1;
long lastNum = 1_000_000;
List<Long> aList = LongStream.range(firstNum, lastNum).boxed()
List<Long> aList = LongStream.rangeClosed(firstNum, lastNum).boxed()
.collect(Collectors.toList());
ForkJoinPool customThreadPool = new ForkJoinPool(4);
long actualTotal = customThreadPool.submit(() -> aList.parallelStream()
.reduce(0L, Long::sum)).get();
assertEquals((lastNum + firstNum) * lastNum / 2, actualTotal);
assertEquals((lastNum + firstNum) * lastNum / 2, actualTotal);
}
@Test