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