Copyonwritearraylist is a thread-safe ArrayList, as the name implies, it will take advantage of the write-time copy technology, it to the shared object to do a read-only operation, we all use a shared object, assuming that there is a variable operation, it will be copied a copy out, Then operate on the new copy.
Therefore, the cost of the variable operation will be larger, of course, before running the replication, the need for an exclusive lock, so that when the replication, there will be no inconsistency, after the replication is complete, release the lock. While doing replication, other threads are able to perform only read operations on older objects, so they do not clog the read operation.
When replication runs out, change the volatile reference so that other threads can see the latest changes.
Original: http://blog.csdn.net/hongchangfirst/article/details/39668723
Author: Hongchangfirst
Hongchangfirst's homepage: http://blog.csdn.net/hongchangfirst
Java copyonwritearraylist Analysis