How does ConcurrentHashMap work internally?

I would read the source of ConcurrentHashMap as it is rather complicated in the detail. In short it has

  • Multiple partitions which can be locked independently. (16 by default)
  • Using concurrent Locks operations for thread safety instead of synchronized.
  • Has thread safe Iterators. synchronizedCollection’s iterators are not thread safe.
  • Does not expose the internal locks. synchronizedCollection does.

Leave a Comment