What is the purpose of coping a new array?
Copying the underlying array guarantees that any iteration of the data structure is safe as the iteration is occurring over an essentially immutable "snapshot" of the data.
Is it for other threads to read the array?
Sort of. More specifically, it is for every thread to be able to safely iterate the array without fear of a ConcurrentModificationException
or other unknown/undefined behavior.
So if a system is high concurrency and most of the threads' actions are reading not writing, it is better to use CopyOnWriteArrayList. Am I right?
No. Only if most of the threads' actions are iterations over the list. If most of the activities are random access based reads, a ReadWriteLock
might be better.
From the javadoc of CopyOnWriteArrayList
This is ordinarily too costly, but may be more efficient than alternatives when traversal operations vastly outnumber mutations, and is useful when you cannot or don't want to synchronize traversals, yet need to preclude interference among concurrent threads.