void () { List<Function<? super String, ? extends Response>> functions = new ArrayList<>(myHandlerMap.size()); // Collection.synchronizedMap object is the internal mutex for the collection. synchronized (myHandlerMap) { myHandlerMap.forEach((func, handler) -> functions.add(func)); } functions.forEach(func -> removeHandler(func)); }