Reference: http://blog.csdn.net/chenssy/article/details/38151189
| Fast Failure Fail-fast |
Security Failure Fail-Safe |
| All of the collection classes below the Java.util package are fast-failing |
All classes under the Java.util.concurrent package are safe and fail. |
| A fast-failing iterator throws a Concurrentmodificationexception exception |
A security failure iterator does not throw an concurrentmodificationexception exception. |
Fast failure
When a thread iterates over a vector, it does not allow other threads to modify the contents of the vector, so that the iterations of the iterator will be inaccurate, such as when using iterator iteration collection, iterator is another thread. It iterates over the collection, and if at this point the Collection.remove (obj) method modifies the contents of the collection, a Concurrentmodificationexception exception occurs. This time the iterator fails quickly.
Like HashMap HashSet ArrayList, it's a quick failure.
Why is it called fast? My understanding: In the iteration, if another thread modifies the contents of the content, it immediately errors, rather than continuing the iteration.
Security failure
Iterator's security failure is based on a copy of the underlying collection, so it is not affected by modifications on the source collection.
Example: Copyonwriterarraylist
A thread-safe variant of ArrayList, where all mutable operations (add, set, and so on) are implemented by a new copy of the underlying array. This class produces more overhead, but in both cases it is well suited for use.
1: When you cannot or do not want to perform synchronous traversal, but you need to exclude conflicts from concurrent threads.
2: When the number of traversal operations greatly exceeds the number of variable operations.
Java notes-fast failure and security failure