Question

As ConcurrentModificationException(CME) can be thrown while strustural change in list during iteration. I see CopyOnWriteArrayList exist in jdk 1.6 to handle with CME but CopyOnWriteLinkedList does not. Whats the reason behind it? i am sure there must be logic behind it.

Was it helpful?

Solution

CopyOnWriteArrayList is based on an array. All mutative operations make a copy of this array, make a change and replace current array with the updated one. Copying an array is fast. Copying a chain of linkes is lots of work

OTHER TIPS

Why CopyOnWriteLinkedList does not exist?

The reason is that a (hypothetical) copy-on-write linked list data structure would not offer any performance advantages over a conventional linked list. (@Evgeniy Dorofeev's answer gives a high level explanation ... )

The reason for having the special concurrent collection classes in the Java class library is that they offer significantly better performance than the simple (non-concurrent) classes for some common use-cases. A "concurrent" list that doesn't perform better than the simple one is a waste of time to implement, and a waste of time to use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top