The question arose about performance and limited resources.
Create a value class for the first three values. Use such a battery to reduce in parallel flow. Limit concurrency according to context (memory, power).
class BronzeSilverGold { int[] values = new int[] {Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE};
Concurrency should be limited in your constellation, so specify N_THREADS in:
try { ForkJoinPool threadPool = new ForkJoinPool(N_THREADS); threadPool.submit(() -> { BronzeSilverGold result = IntStream.of(...).parallel().collect( BronzeSilverGold::new, (bsg, n) -> BronzeSilverGold::add, (bsg1, bsg2) -> bsg1.merge(bsg2)); ... }); } catch (InterruptedException | ExecutionException e) { prrtl(); }
source share