Merge pull request #10542 from sk1418/threadPool

shutdown the pool
This commit is contained in:
Eric Martin 2021-03-13 14:00:26 -06:00 committed by GitHub
commit 74aebe1a62
1 changed files with 8 additions and 6 deletions

View File

@ -21,14 +21,16 @@ public class ThreadPoolInParallelStreamIntegrationTest {
long lastNum = 1_000_000;
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);
try {
long actualTotal = customThreadPool
.submit(() -> aList.parallelStream().reduce(0L, Long::sum))
.get();
assertEquals((lastNum + firstNum) * lastNum / 2, actualTotal);
} finally {
customThreadPool.shutdown();
}
}
@Test