void () { List<T> disposeQueue; List<ProgressIndicatorEx> indicatorsQueue; synchronized (myLock) { //running task is not included, we must not dispose it if it is (probably) running disposeQueue = new ArrayList<>(myTasksQueue); // the keys also include a running task(s) indicatorsQueue = new ArrayList<>(myProgresses.values()); myTasksQueue.clear(); myProgresses.clear(); myThreadContexts.clear(); } cancelIndicatorSafe(indicatorsQueue); disposeSafe(disposeQueue); }