void () { final Ref<Long> nextTime = Ref.create(Long.MAX_VALUE); synchronized (myLock) { if (myTimeoutHandlers.isEmpty()) { return; } for (TimeoutHandler value : myTimeoutHandlers.values()) { nextTime.set(Math.min(nextTime.get(), value.myLastTime)); } } final int delay = (int)(nextTime.get() - System.currentTimeMillis() + 100); LOG.debug("schedule timeout check in " + delay + "ms"); if (delay > 10) { myTimeoutAlarm.cancelAllRequests(); myTimeoutAlarm.addRequest(() -> checkTimeout(), delay); } else { checkTimeout(); } }