FAIL FAST ITERATOR VS FAIL SAFE ITERATOR

Veröffentlicht am: 19 Mai 2018
auf dem Kanal: 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


Auf dieser Seite können Sie das Online-Video FAIL FAST ITERATOR VS FAIL SAFE ITERATOR mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Sudipto Roy 19 Mai 2018 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 2,199 Mal angesehen und es wurde von 31 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!