1.

What Is Fail Fast Iterator?

Answer»

An iterator is considered fail-fast if it throws a CONCURRENTMODIFICATIONEXCEPTION under either of the following two conditions:

  • In multi-threaded environment, if one thread is trying to modify a Collection while another thread is iterating over it.
  • EVEN with SINGLE thread, if a thread modifies a collection directly while it is iterating over the collection with a fail-fast iterator, the iterator will throw this EXCEPTION.

fail-fast iterator will throw a ConcurrentModificationException if the underlying collection is structurally modified in any way except through the iterator's own remove or add (if applicable as in list-iterator) methods.

Note that structural modification is any operation that adds or deletes one or more elements; merely SETTING the value of an element (in case of list) or changing the value associated with an existing key (in case of map) is not a structural modification.

An iterator is considered fail-fast if it throws a ConcurrentModificationException under either of the following two conditions:

fail-fast iterator will throw a ConcurrentModificationException if the underlying collection is structurally modified in any way except through the iterator's own remove or add (if applicable as in list-iterator) methods.

Note that structural modification is any operation that adds or deletes one or more elements; merely setting the value of an element (in case of list) or changing the value associated with an existing key (in case of map) is not a structural modification.



Discussion

No Comment Found