void () { long delay = TOO_LONG_EXECUTION_MS; Map<ExternalSystemTaskId, Long> newState = new HashMap<>(); Map<ExternalSystemTaskId, Long> currentState = new HashMap<>(myTasksInProgress); if (currentState.isEmpty()) { return; } for (Map.Entry<ExternalSystemTaskId, Long> entry : currentState.entrySet()) { long diff = System.currentTimeMillis() - entry.getValue(); if (diff > 0) { delay = Math.min(delay, diff); newState.put(entry.getKey(), entry.getValue()); } else { // Perform explicit check on whether the task is still alive. if (myFacadeManager.isTaskActive(entry.getKey())) { newState.put(entry.getKey(), System.currentTimeMillis() + TOO_LONG_EXECUTION_MS); } } } myTasksInProgress.clear(); myTasksInProgress.putAll(newState); if (!newState.isEmpty()) { myAlarm.cancelAllRequests(); myAlarm.addRequest(() -> update(), delay); } }