private void tickIfNecessary ( ) { final long oldTick = lastTick . get ( ) ; final long newTick = clock . tick ( ) ; final long age = newTick - oldTick ; if ( age > TICK_INTERVAL ) { final long newIntervalStartTick = newTick - age % TICK_INTERVAL ; if ( lastTick . compareAndSet ( oldTick , newIntervalStartTick ) ) { final long requiredTicks = age / TICK_INTERVAL ; for ( long i = 0 ; i < requiredTicks ; i ++ ) { m15Rate . tick ( ) ; m120Rate . tick ( ) ; } } } }
Updates the moving averages as needed .