What is the Difference between concurrent HashMap and Synchronized HashMap..? | SoloLearn: Learn to code for FREE!

+1

What is the Difference between concurrent HashMap and Synchronized HashMap..?

About HashMap

2/4/2020 6:28:30 AM

goutham thota

1 Answer

New Answer

+2

Both are thread-safe objects but they work differently. ConcurrentHashMap does not apply a lock on read operations, only locks down a portion of the data for writes (this is called lock striping). This results in very high scalability and weaker consistency. Collections.synchronizedMap() locks the entire object for both read and write operations, and you need to put all code accessing this Map, in synchronized blocks. Read more here: https://stackoverflow.com/questions/1291836/concurrenthashmap-vs-synchronized-hashmap