Copy-on-write container

Source: Internet
Author: User

Copy-on-write abbreviation Cow, is a kind of optimization strategy used in program design.

There are two types of cow containers in the JDK: copyonwritearraylist and Copyonwritearrayset,cow containers are very useful and can be used in very many concurrent scenarios.

The Copyonwrite container is the container that is copied when it is written. The popular understanding is that when we add elements to a container, we do not add them directly to the current container, but instead copy the current container, copying a new container.

The advantage of this is that we can read the Copyonwrite container concurrently, without having to lock it, because the current container does not add any elements. So the Copyonwrite container is also a reading and writing separation of the mind, read and write containers.

This also shows that the application scenario of cow container is best to read and write less scenes, otherwise it will produce a lot of memory duplication and recycling problems.

     Public Static void Main (string[] args) {        // containers are used         in the same way as the list and/ or write operations of multiple threads, There will be a re-entry lock to ensure that the write operation does not occur with data inconsistency.        New copyonwritearraylist<string>();        CopyonwritearraysetNew copyonwritearrayset<string>();            }

Copy-on-write container

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.