How does ConcurrentHashMap work internally?

Viewed 49427

I was reading the official Oracle documentation about Concurrency in Java and I was wondering what could be the difference between a Collection returned by

public static <T> Collection<T> synchronizedCollection(Collection<T> c);

and using for example a

ConcurrentHashMap. I'm assuming that I use synchronizedCollection(Collection<T> c) on a HashMap. I know that in general a synchronized collection is essentially just a decorator for my HashMap so it is obvious that a ConcurrentHashMap has something different in its internals. Do you have some information about those implementation details?

Edit: I realized that the source code is publicly available: ConcurrentHashMap.java

6 Answers

ConcurrentHashMap implements ConcurrentMap which provides the concurrency. Deep internally its iterators are designed to be used by only one thread at a time which maintains the synchronization. This map is used widely in concurrency.

Related