What is concurrent collections in java
As we know most of the collection classes are not thread-safe like ArrayList that is why java launched
java.util.concurrent package includes a number of additions to the Java Collections Framework.
why concurrent collection came?
At the time of iterating any collection classes if another thread wants to modify collection data then we will get ConcurrentModificationException.But in case of new concurrent collection classes we can add element at the time iterating element without any exception.
What is problem with existing thread-safe collection classes
Performance wise existing thread-safe classes are not good because they locks whole object instead of part of object.
Advantage of Concurrent Collection
- Every concurrent classes are thread-safe.
- Performance is far better than existing thread-safe classes.
- It has different locking mechanism.
- While iterating collection element we can modify data means we will not get ConcurrentModificationException.