У меня есть список идентификаторов продуктов, я хочу разделить его на подсписки размером 3.
Код: Выделить всё
List productBatches = StreamSupport.stream(Iterables.partition(productIds, 3).spliterator(), true).toList();
List
productPrices = productBatches.parallelStream()
.map(batch -> productPriceService.getProductsPrices(batch))
.flatMap(List::stream)
.toList();
Код: Выделить всё
List list = new java.util.ArrayList(List.of());
for (int i = 0; i < 40; i++) {
list.add("test" + i);
}
List listBatches = StreamSupport.stream(Iterables.partition(list, 3).spliterator(), true).toList();
List testStrings = listBatches.parallelStream()
.map(batch -> {
System.out.println("Batch: " + batch.toString());
return String.join(",", batch);
})
.toList();
Подробнее здесь: https://stackoverflow.com/questions/793 ... n-parallel
Мобильная версия