void (long sinceLastUpdate) { List<Pair<String, Long>> times = takeSnapshot(); String text = " %CPU Subsystem\n\n" + StreamEx.of(times) .filter(p -> p.second > 10) .sorted(Comparator.comparing((Pair<String, Long> p) -> p.second).reversed()) .limit(8) .map(p -> String.format("%5.1f %s", (double) p.second*100 / sinceLastUpdate, p.first)) .joining("\n"); ApplicationManager.getApplication().invokeLater(() -> { textArea.setText(text); textArea.setCaretPosition(0); }, ModalityState.any()); }