Friday, April 7, 2017

Why use a concurrent collection classes in java?

Concurrent collection classes is extremely convenient to use it without using Thread class.

Advantages:

 1. Prevents mistake from own custom implementation such as if we forgot to synchronize one of the accessor methods.
2. Concurrent collections avoid unnecessary synchronizations.
3. The concurrent classes were created to help avoid common issues in which multiple
threads are adding and removing objects from the same collections

The following code program is alternate version of our implementation that does not use the synchronized key word.

public class ConcurrentExample{

 private Map<String, String> map = new ConcurrentHashMap<>();

}

No comments: