Java 11 does not have AutoClosable on ForkJoinPool (that's a pity).
This commit is contained in:
parent
ad3998bb61
commit
0e4858a184
@ -21,7 +21,8 @@ public class StreamExample {
|
||||
// Huge number of threads!
|
||||
getPeople().parallel().mapToInt(Person::getAge).average().ifPresent(System.out::println);
|
||||
// Better solution, limiting the number of threads
|
||||
try (var pool = new ForkJoinPool(8)) {
|
||||
// IDEA complains about try-with-resources, but that does not work with Java 11 (try higher)
|
||||
@SuppressWarnings("resource") var pool = new ForkJoinPool(8);
|
||||
var maybeAverageAgeFuture = pool.submit(
|
||||
() -> getPeople().parallel().mapToInt(Person::getAge).average()
|
||||
);
|
||||
@ -34,8 +35,6 @@ public class StreamExample {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Stream<Person> getPeople() {
|
||||
var personPrototype = Person.builder()
|
||||
.housing(
|
||||
|
Loading…
Reference in New Issue
Block a user