According to my understanding, parallel collection classes prefer a more synchronized assembly, because parallel collection classes do not take locks for the entire collection object. Instead, it blocks a small segment of the collection object.
This is true for some collections, but not for all. The map returned by Collections.synchronizedMap blocks the entire map around each operation, while ConcurrentHashMap blocks only one hash bit for some operations or may use a non-blocking algorithm for others.
For other collections, the algorithms used, and therefore the tradeoffs, are different. This is especially true for lists returned by Collections.synchronizedList compared to CopyOnWriteArrayList . As you noted, both synchronizedList and CopyOnWriteArrayList lock the entire array during write operations. So why so different?
The difference arises if you look at other operations, such as iterating over each element of the collection. The documentation for Collections.synchronizedList says:
It is imperative that the user manually synchronizes the returned list when iterating over it:
List list = Collections.synchronizedList(new ArrayList()); ... synchronized (list) { Iterator i = list.iterator();
Failure to follow this advice can lead to deterministic behavior.
In other words, iterating over a synchronizedList is not thread safe unless you manually block it. Please note that when using this method, all operations with other threads in this list, including iteration, retrieval, collection, addition and deletion, are blocked. Only one thread at a time can do anything with this collection.
In contrast, the doc for CopyOnWriteArrayList says
The snapshot style iterator method uses a reference to the state of the array at the point at which the iterator was created. This array never changes during the life of the iterator, so no interference is possible, and the iterator is guaranteed not to throw a ConcurrentModificationException . The iterator will not display additions, deletions, or changes to the list since the creation of the iterator.
The operations of other threads in this list can be performed simultaneously, but the iteration is not affected by changes made by other threads. Thus, even though write operations block the entire list, CopyOnWriteArrayList can still provide higher throughput than a regular synchronizedList . (Provided that there is a large share of reads and crawls for writing.)