Java Concurrency Programming-copyonwritearraylist

Source: Internet
Author: User

Copyonwritearraylist principle

The first time each write operation, the array copy is copied, and assigned to arrays

Read operation read No lock

Write Operation plus Lock

Reentrantlock

Because it is a heavy operation to copy an array every time it is written,

Copyonwritearraylist is suitable for reading and writing less.

The source code for the Add method is as follows:

 Public BooleanAdd (e e) {FinalReentrantlock lock = This. Lock;    Lock.lock (); Try{object[] elements=GetArray (); intLen =elements.length; Object[] Newelements= arrays.copyof (elements, Len + 1); Newelements[len]=e;        SetArray (newelements); return true; } finally{lock.unlock (); }    }

Reference article:

http://blog.csdn.net/wjwj1203/article/details/8109000

Http://www.cnblogs.com/sunwei2012/archive/2010/10/08/1845656.html

Java Concurrency Programming-copyonwritearraylist

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.