What is difference between fail-fast and fail-safe?

Technology CommunityCategory: JavaWhat is difference between fail-fast and fail-safe?
VietMX Staff asked 4 years ago

The Iterator’s fail-safe property works with the clone of the underlying collection and thus, it is not affected by any modification in the collection. All the collection classes in java.util package are fail-fast, while the collection classes in java.util.concurrent are fail-safe. Fail-fast iterators throw a ConcurrentModificationException, while fail-safe iterator never throws such an exception.