FAIL FAST ITERATOR VS FAIL SAFE ITERATOR

Pubblicato il: 19 maggio 2018
sul canale di: Sudipto Roy
2,199
31

Is Iterator a class?
What is ConcurrentModificationException?
What is fail-fast property?
What is UnsupportedOperationException?
Difference b/w fail-fast & fail-safe iterators?
Concurrent Modification : Modification of an object concurrently when a task is already processing it

Fail-fast iterators

If a structural modification is detected then this iterator throws ConcurrentModificationException
Structural modification includes addition, removal or updating of elements while a collection is being iterated over.
Examples include Iterators on ArrayList, HashMap

Fail-safe iterators

Even if a structural modification is detected then this iterator does not throw an exception
Structural modification done on actual collection goes unnoticed by these iterators.
So while iterating up-to-date data is not guaranteed
Examples include Iterators on ConcurrentHashMap, CopyOnWriteArrayList

How fail-fast iterators work?

When an Iterator is created, it makes a copy of underlying structure
It then iterates over that snapshot
Any changes to the collection does not get reflected in the snapshot
So interference is not possible & it will never throw ConcurrentModificationException
remove, set and add operations on iterators are not supported. These methods throw UnsupportedOperationException.

fail-safe iterator & weakly consistent
In case of ConcurrentHashMap, it does not work on a separate copy although it is NOT fail-fast
It is called weakly-consistent
Weakly-consistent means it can tolerate concurrent modification while traversing and may reflect (but not guaranteed) concurrent modification


In questa pagina del sito puoi guardare il video online FAIL FAST ITERATOR VS FAIL SAFE ITERATOR della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Sudipto Roy 19 maggio 2018, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 2,199 volte e gli è piaciuto 31 spettatori. Buona visione!