문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top