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

  Quick failed:

  In the previous section, list the collection contains rapid failure when using iterates over a collection of objects, if the traversal of the structure of a collection of objects were modified (add, delete),

Concurrent Modification Exception is thrown.

  Collections under java.util package are fail-fast, changes can not occur in concurrent multithreading (modified iteration).

  Security Failure: 

   Fail-safe mechanism using a collection container, not directly access the contents of the collection during traversal, but the first copy of the original contents of the collection, to traverse on a copy of the collection.

       Principle: Because the original copy of iteration is set to traverse, so that during traversal of modifications made to the original set are not to be detected by the iterator will not be triggered Concurrent Modification Exception.

         Disadvantages: Advantages copying of contents is avoided based Concurrent Modification Exception, but again, do not have access to the iterator modified content,

Namely: iterates over a copy of the moment began to walk through the collection to get, modify the original collection iterator occur during traversal is not known.

  Containers are safe under the java.util.concurrent package fails, you can use a multithreaded concurrent, concurrent modifications.

Guess you like

Origin www.cnblogs.com/xp0813/p/11074310.html