protected long adjustRunLoopFrequency ( long processingStartTimeNanos , long processingEndTimeNanos ) throws InterruptedException { long endTimeNanos = processingEndTimeNanos ; if ( fetchIntervalMillis != 0 ) { long processingTimeNanos = processingEndTimeNanos - processingStartTimeNanos ; long sleepTimeMillis = fetchIntervalMillis - ( processingTimeNanos / 1_000_000 ) ; if ( sleepTimeMillis > 0 ) { Thread . sleep ( sleepTimeMillis ) ; endTimeNanos = System . nanoTime ( ) ; shardMetricsReporter . setSleepTimeMillis ( sleepTimeMillis ) ; } } return endTimeNanos ; }
Adjusts loop timing to match target frequency if specified .