In this blog post we will talk about What are fail-fast and fail-safe Iterator? One thing I would like to make you clear here is that this post only listed out the difference between fail-fast and fail-safe Iterator but not the detail explanation with example.
- Fail-safe Iterator is “Weakly Consistent” and does not throw any exception if collection is modified structurally during the iteration.
- Such Iterator -may work on clone of collection instead of original collection such as in CopyOnWriteArrayList
- Most collections under util.concurrent offer fail-safe Iterators to its users and that’s by Design.
- Fail safe collections should be preferred while writing multi-threaded applications to avoid conurrency related issues.
- Fail Safe Iterator is guaranteed to list elements as they existed upon construction of Iterator, and may reflect any modifications subsequent to construction (without guarantee).
You may also like:
Can we call static method with null object?
Can we override static method in Java?
What will be the output of following java program?
What is the difference Between java.util.Date and java.sql.Date in Java ?
Why Prime Numbers are considered in writing certain algorithms like hashcode()?
That’s all about What are fail-fast and fail-safe Iterator?
If you have any feedback or suggestion please feel free to drop in blow comment box.