Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3
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
4th Feb 2020, 7:04 AM
Tibor Santa
Tibor Santa - avatar