void () { LOG.debug("Checking timeout"); final List<TimeoutHandler> timedOut = new ArrayList<>(); synchronized (myLock) { long time = System.currentTimeMillis(); ObjectIterator<Int2ObjectMap.Entry<TimeoutHandler>> iterator = myTimeoutHandlers.int2ObjectEntrySet().iterator(); while (iterator.hasNext()) { Int2ObjectMap.Entry<TimeoutHandler> entry = iterator.next(); TimeoutHandler b = entry.getValue(); if (time > b.myLastTime) { timedOut.add(b); iterator.remove(); } } } for (TimeoutHandler handler : timedOut) { LOG.debug("performing timeout action: " + handler.myAction); handler.myAction.run(); } scheduleTimeoutCheck(); }