void (final @NotNull UiActivity activity) { if (!myActivities.containsKey(activity)) return; myQueuedToRemove.add(activity); Runnable runnable = () -> { if (!myQueuedToRemove.contains(activity)) return; myQueuedToRemove.remove(activity); myActivities.remove(activity); myContainer.onActivityRemoved(this, activity); onReady(); }; SwingUtilities.invokeLater(runnable); }