1.

What Is Difference Between Fail-fast And Fail-safe?

Answer»

You have understood fail-fast in PREVIOUS QUESTION. Fail-safe iterators are just opposite to fail-fast. They NEVER fail if you modify the underlying collection on which they are ITERATING, because they work on CLONE of Collection instead of original collection and that’s why they are called as fail-safe iterator. Iterator of CopyOnWriteArrayList is an example of fail-safe Iterator also iterator written by ConcurrentHashMap keySet is also fail-safe iterator and never throw ConcurrentModificationException.

You have understood fail-fast in previous question. Fail-safe iterators are just opposite to fail-fast. They never fail if you modify the underlying collection on which they are iterating, because they work on clone of Collection instead of original collection and that’s why they are called as fail-safe iterator. Iterator of CopyOnWriteArrayList is an example of fail-safe Iterator also iterator written by ConcurrentHashMap keySet is also fail-safe iterator and never throw ConcurrentModificationException.



Discussion

No Comment Found