Javarevisited Newsletter

Javarevisited Newsletter

Share this post

Javarevisited Newsletter
Javarevisited Newsletter
How ConcurrentHashMap works in Java?

How ConcurrentHashMap works in Java?

and difference between a synchronized map and concurrentHashMap

javinpaul's avatar
javinpaul
Mar 07, 2024
∙ Paid
7

Share this post

Javarevisited Newsletter
Javarevisited Newsletter
How ConcurrentHashMap works in Java?
1
3
Share

Hello guys, how HashMap work in Java, and How ConcurrentHashMap works in Java are two of the popular questions in Java interviews. I have seen it many times and even asked about it a couple of times.

Since a lot of you requested me to share core Java interview questions, I have decided to write at least one post about them every week and in this post, I will talk about How ConcurrentHashMap work and what is difference between a synchronized Map and ConcurrentHashMap in Java.

ConcurrentHashMap is a class in Java that provides a thread-safe implementation of the Map interface. It was introduced in Java 5 to address the need for a concurrent and scalable map data structure. The primary goal ConcurrentHashMap is to allow multiple threads to read and write to the map concurrently without the need for external synchronization.

Here are some key features and aspects of how ConcurrentHashMap works:

  1. Segmentation: ConcurrentHashMap is divided into segments, and each segment acts as an independent hash table. The number of segments is determined by the concurrencyLevel specified during the creation of the ConcurrentHashMap. Each segment is essentially a separate hash table, and different segments can be operated on concurrently by different threads.

    Here is how a segment looks like:

Keep reading with a 7-day free trial

Subscribe to Javarevisited Newsletter to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 javinpaul
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share