Friday, October 6, 2017

Fail Fast and Fail safe Iterator

Brief Introduction To Fail Fast And Fail Safe Systems :

A system is called fail-fast if it is shut down immediately when an error occurred. These systems don’t carry on with the errors. They immediately stop operating when a fault is occurred in the system. The errors in the fail-fast systems are immediately exposed. But, fail-safe systems are not like that. They don’t stop operating even when a fault is occurred in the system. They continue the operation by hiding the errors. They don’t expose the errors immediately. They carry on with the errors. Which one is the best system is always the most discussed topic in the system design field. In this post, we limit our discussion to Fail Fast and Fail Safe Iterators in java.

Fail-Fast Iterators
Fail-Safe Iterators
Fail-Fast iterators doesn’t allow modifications of a collection while iterating over it.
Fail-Safe iterators allow modifications of a collection while iterating over it.
These iterators throw ConcurrentModificationException if a collection is modified while iterating over it.
These iterators don’t throw any exceptions if a collection is modified while iterating over it.
They use original collection to traverse over the elements of the collection.
They use copy of the original collection to traverse over the elements of the collection.
These iterators don’t require extra memory.
These iterators require extra memory to clone the collection.
Ex : Iterators returned by ArrayListVectorHashMap.
Ex : Iterator returned by ConcurrentHashMap.

References :

http://javaconceptoftheday.com/fail-fast-and-fail-safe-iterators-in-java-with-examples/





No comments:

Post a Comment