Fast failure (fail-fast) and the security failure (fail-safe)

A rapid failure (fail-fast)

  1. Principle
    when traversing a collection iterator, iterator maintains a modCount variable, when traversing a front element, it will determine whether the value modCount expectedModCount, if it is expectedModCount through the results returned; otherwise, an exception is thrown ConcurrentModificationException terminate traversal.

  2. HashMap rapid failure of
    the HashMap Iterator iterator is a quick failure.
    When traversing a collection, if the modification (add, delete, change) of the elements of the collection, exception is thrown ConcurrentModificationException

II. Security failure (fail-safe)

  1. Principle
    iterator while traversing the collection, the first copy of the original elements of the set, and then the copy of the collection to traverse. Therefore, when traversing, the original set of modifications is not detected by the iterator.

  2. Security failure of Hashtable
    Hashtable Enumerator iterator uses the security fails.

Published 70 original articles · won praise 4 · Views 6375

Guess you like

Origin blog.csdn.net/qq_44837912/article/details/104396849