Java threads --CopyOnWrite containers

Original: Reprinted indicate the original address https://www.cnblogs.com/fanerwei222/p/11871602.html

Java threads --CopyOnWrite containers

 CopyOnWrit container is mainly used for reading and writing little scene, whitelist, blacklist, the type of access and update scenarios, the principle is that if you want to read about a container, can be read directly, if you want to overwrite the contents of a container inside when , you need to get the container plus a write lock, and then copy a copy, and then rewrite this copy, and then copy the original pointer to this container, complete rewrite.

public static void main(String[] args) {
    CopyOnWriteArrayList copyOnWriteArrayList = new CopyOnWriteArrayList();
    /**
     * Batch add, reduce the number of containers copy
     */
    copyOnWriteArrayList.addAll(new ArrayList());
}

 

Guess you like

Origin www.cnblogs.com/fanerwei222/p/11871602.html