13 Feb 2018

Difference between CopyOnWriteArraySet and synchronizedSet().

CopyOnWriteArraySet
synchronizedSet()
It is thread safe because every update operation will perform on separate cloned copy.
It is Thread safe beacause at a time only one thread can perform Operation.
While one thread iterating Set , the other Threads are allowed to modify and we wont get ConcurrentModificationException.
While one thread iterating Set , the other Threads are not allowed to modify Set and we will get ConcurrentModificationException.
Iterator is Fail-Safe.
Iterator is Fail-Fast.
Iterator can performance only read operation and cannot perform remove operation otherwise we will get runtime exception saying UnsupportedOperationException.
Iterator can perform both read and remove operation.
Introduced in 1.5 version.
Introduced in 1.7 version.