// iterate safely (& quickly) in the face of concurrent modifications static IterableIterator concurrentlyIterateValues(NavigableMap map) { ret concurrentlyIterateValues(map, map); } static IterableIterator concurrentlyIterateValues(final NavigableMap map, O mutex) { ret iteratorFromFunction(new F0() { Iterator it = keys(map).iterator(); A key; B get() { synchronized(mutex) { try { if (!it.hasNext()) null; ret map.get(key = it.next()); } catch (ConcurrentModificationException e) { print("Re-iterating"); it = map.tailMap(key, false).keySet().iterator(); if (!it.hasNext()) null; ret map.get(key = it.next()); // Can't throw another exception } } } }); }