To be extra-defensive I'd apply a Math.min( batchIndexingThreads, rootEntities.length) as we don't check for upper boundary of the user parameter.