@Override public void run() { Iterator<Map.Entry<Object, RateLimiterExecutor>> it = currentLimiters.entrySet().iterator(); long now = Clock.lastKnownForwardProgressingMillis(); while (it.hasNext()) { Map.Entry<Object, RateLimiterExecutor> e = it.next(); if (now - e.getValue().getLastScheduleTime() > LIMITER_IDLE_TIMEOUT) { // if optimistic check above failed, we must remove in `compute` to ensure // no tasks are being submitted while we are removing the limiter currentLimiters.computeIfPresent(e.getKey(), (k, v) -> { if (now - v.getLastScheduleTime() > LIMITER_IDLE_TIMEOUT) { return null; } else { return v; } }); } } if (! currentLimiters.isEmpty()) { signalToRun(); } } }
limiterChecker.signalToRun();
this.addKeyToThreadName = addKeyToThreadName; this.currentLimiters = new ConcurrentHashMap<>(CONCURRENT_HASH_MAP_INITIAL_SIZE); this.limiterChecker = new LimiterChecker(scheduler, LIMITER_IDLE_TIMEOUT / 2);
limiterChecker.signalToRun();
this.addKeyToThreadName = addKeyToThreadName; this.currentLimiters = new ConcurrentHashMap<>(CONCURRENT_HASH_MAP_INITIAL_SIZE); this.limiterChecker = new LimiterChecker(scheduler, LIMITER_IDLE_TIMEOUT / 2);
@Override public void run() { Iterator<Map.Entry<Object, RateLimiterExecutor>> it = currentLimiters.entrySet().iterator(); long now = Clock.lastKnownForwardProgressingMillis(); while (it.hasNext()) { Map.Entry<Object, RateLimiterExecutor> e = it.next(); if (now - e.getValue().getLastScheduleTime() > LIMITER_IDLE_TIMEOUT) { // if optimistic check above failed, we must remove in `compute` to ensure // no tasks are being submitted while we are removing the limiter currentLimiters.computeIfPresent(e.getKey(), (k, v) -> { if (now - v.getLastScheduleTime() > LIMITER_IDLE_TIMEOUT) { return null; } else { return v; } }); } } if (! currentLimiters.isEmpty()) { signalToRun(); } } }