Example & Tutorial understanding programming in easy ways.

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

1 Fail-fast Iterators fail as soon as they realized that structure of Collection has been changed since iteration has begun. ( Structural changes means adding, removing or updating any element from collection while one thread is Iterating over that collection ).
2 Fail-fast behavior is implemented by keeping a modification count and if iteration thread realizes the change in modification count it throws ConcurrentModificationException.

1 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.
2 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.

Read More →
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!