void () { for (long id : threadBean.getAllThreadIds()) { long cpuTime = threadBean.getThreadCpuTime(id); long prev = lastThreadTimes.put(id, cpuTime); if (prev != 0 && cpuTime > prev) { String subsystem = getSubsystemName(id); subsystemToSamples.put(subsystem, subsystemToSamples.getLong(subsystem) + cpuTime - prev); } } long now = System.currentTimeMillis(); long sinceLastUpdate = now - lastUiUpdate; if (sinceLastUpdate > 2_000) { lastUiUpdate = now; scheduleUiUpdate(sinceLastUpdate); } }