void (@NotNull BusyImpl busy, @NotNull UiActivity activity) { if (myRemovingActivityNow) return; final Map<BusyImpl, Set<UiActivity>> toRemove = new HashMap<>(); try { myRemovingActivityNow = true; myActivities.remove(activity); for (BusyImpl each : myObject2Activities.keySet()) { if (each != busy) { each.removeActivity(activity); } if (each.isReady()) { final Set<UiActivity> activities = myObject2Activities.get(busy); toRemove.put(busy, activities); } } } finally { for (BusyImpl each : toRemove.keySet()) { final Set<UiActivity> activities = myObject2Activities.remove(each); myActivities2Object.remove(activities); } myRemovingActivityNow = false; } }