IntStream tstream = IntStream.rangeClosed(1, 2);
Collector<Object, ?, Map<Object, List<Object>>> collector = Collectors.groupingBy(i -> Thread.currentThread());
ForkJoinPool pool = new ForkJoinPool(42);
Map<Object, List<Object>> coll;
try {
coll = pool.submit(() -> tstream.boxed().parallel().collect(collector)).get();
}
catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
coll = null;
}
coll.replaceAll((thread, list) -> Arrays.asList(list.size()));