---
title: "difference between ConcurrentHashMap and Collections.synchronizedMap(Map)?"  
description: "difference between ConcurrentHashMap and Collections.synchronizedMap(Map)?"  
author: "Anonymous User"  
published: 2015-07-29  
updated: 2015-07-29  
canonical: https://www.mindstick.com/forum/23384/difference-between-concurrenthashmap-and-collections-synchronizedmap-map  
category: "java"  
tags: ["java", "collection", "threading"]  
reading_time: 2 minutes  

---

# difference between ConcurrentHashMap and Collections.synchronizedMap(Map)?

I have a Map which is to be modified by several [threads](https://www.mindstick.com/blog/11678/threads-in-java) concurrently.\
There seem to be three different [synchronized](https://www.mindstick.com/interview/2499/what-is-the-purpose-of-synchronized-block) Map implementations in the [Java API](https://www.mindstick.com/interview/1935/what-is-the-java-api):\
1.Hashtable2.Collections.synchronizedMap(Map)3.ConcurrentHashMapFrom what I understand, Hashtable is an old [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp) (extending the obsolete [Dictionary](https://www.mindstick.com/articles/1500/hashtable-and-dictionary-in-c-sharp) [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp)), which has been adapted later to fit the Map interface. While it is synchronized, it seems to have serious [scalability](https://www.mindstick.com/blog/140/performance-and-scalability-characteristics-of-mysql) [issues](https://www.mindstick.com/articles/12944/mattresses-for-kids-and-mothers-should-meet-certain-criteria-issues-you-should-consider) and is discouraged for new projects.\
But what about the other two? What are the [differences](https://www.mindstick.com/articles/12918/cat-5e-vs-cat-6a-understanding-the-major-differences) between Maps returned by Collections.synchronizedMap(Map) and ConcurrentHashMaps? Which one fits which situation?

## Replies

### Reply by Anonymous User

For your needs, use ConcurrentHashMap. It allows concurrent modification of the Map from several threads without the need to block them. Collections.synchronizedMap(map) creates a blocking Map which will degrade performance, albeit ensure consistency (if used properly).\
Use the second option if you need to ensure data consistency, and each thread needs to have an up-to-date view of the map. Use the first if performance is critical, and each thread only inserts data to the map, with reads happening less frequently.\
The "scalability issues" for Hashtable are present in exactly the same way in Collections.synchronizedMap(Map) - they use very simple synchronization, which means that only one thread can access the map at the same time.\
This is not much of an issue when you have simple inserts and lookups (unless you do it extremely intensively), but becomes a big problem when you need to iterate over the entire Map, which can take a long time for a large Map - while one thread does that, all others have to wait if they want to insert or lookup anything.\
The ConcurrentHashMap uses very sophisticated techniques to reduce the need for synchronization and allow parallel read access by multiple threads without synchronization and, more importantly, provides an Iterator that requires no synchronization and even allows the Map to be modified during interation (though it makes no guarantees whether or not elements that were inserted during iteration will be returned).


---

Original Source: https://www.mindstick.com/forum/23384/difference-between-concurrenthashmap-and-collections-synchronizedmap-map

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
