Today's Question:  What's your opinion about Alibaba mooncake incident?        GIVE A SHOUT

Technical Article => Programming =>  Java

Difference between ConcurrentHashMap and Hashtable

  sonic0002      2013-11-18 08:06:54      31,838    3    0

Both ConcurrentHashMap and Hashtable are Collection classes for storing key value pairs and they both provide fast element search with a supplied key. They have much in common. However, we will not discuss the similarities between them here, instead we will focus on the differences between them.

ConcurrentHashMap and Hashtable are both thread safe. But the mechanism for thread safe is different between them. Hashtable is synchronized, it utilizes the synchronization mechanism; while ConcurrentHashMap uses segmentation to lock the data, it uses concurrent locks operations for thread safety instead of synchronized.

Since ConcurrentHashMap introduced concept of segmentation , how large it becomes only certain part of it get locked to provide thread safety so many other readers can still access map without waiting for iteration to complete.

So if you want to store large amount of data in a multithreaded program, you should consider to choose ConcurrentHashMap.

CONCURRENTHASHMAP HASHTABLE

  SAVE AS PDF   MARK AS READ   MARK AS IMPORTANT

  RELATED


  3 COMMENTS


hi [Reply]@ 2013-11-22 05:00:23

<script>

alert("Hello");

</script>

hi [Reply]@ 2013-11-25 21:57:33

<script>alert("Hello")</script>

Input Validation needed  [Reply]@ 2013-11-25 23:07:03

Hi,

Input validation is needed for Nickname :)

 

 


  WRITE ARTICLE

Stackoverflooooooow

By sonic0002
Stackoverflow is celebrating its 10 million questions. This is a big milestone for this question-answer website. Here is the page to record all these amazing moments. http://stackoverflow.com/10m