public static void loopBlocks ( int start , int endExclusive , IntRangeConsumer consumer ) { final ForkJoinPool pool = BoofConcurrency . pool ; int numThreads = pool . getParallelism ( ) ; int range = endExclusive - start ; if ( range == 0 ) // nothing to do here! return ; if ( range < 0 ) throw new IllegalArgumentException ( "end must be more than start. " + start + " -> " + endExclusive ) ; // Did some experimentation here. Gave it more threads than were needed or exactly what was needed // exactly seemed to do better in the test cases int blockSize = Math . max ( 1 , range / numThreads ) ; try { pool . submit ( new IntRangeTask ( start , endExclusive , blockSize , consumer ) ) . get ( ) ; } catch ( InterruptedException | ExecutionException e ) { throw new RuntimeException ( e ) ; } }
Splits the range of values up into blocks . It s assumed the cost to process a block is small so more can be created .