FAIL FAST ITERATOR VS FAIL SAFE ITERATOR

Publié le: 19 mai 2018
sur la chaîne: 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


Sur cette page du site, vous pouvez voir la vidéo en ligne FAIL FAST ITERATOR VS FAIL SAFE ITERATOR durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Sudipto Roy 19 mai 2018, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 2,199 fois et il a aimé 31 téléspectateurs. Bon visionnage!