I got somewhat confused on my understanding, when the below things asked to me in a quiz:
1)ConcurrentHashMap
: As per my understanding, there is no lock to get values(corresponding to a key) from this map.
Question is : if this is true, suppose t1 is writing(by taking lock on a Segment/bucket) and t2 tries to read same, t2 will not get the correct value, and thus inconsistent value to t2
2)HashMap
: As per my understanding,before a element is added to a hashbucket, the hashvalue H is calculated as hashcode%16 (gives values from 0 to 15) for the key (key.hashcode()) and then added to the bucket whose hashvalue is H
Note : there are 16 buckets(default implementation), which represents a ArrayList
of LinkedList
|0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |10 | 11 |12 |13 |14 |15 |
ArrayList at 2000(memory address)
You can very well say this is duplicate of Segmentation in ConcurrentHashMap, Regarding internal working of concurrent hashmap, HashMap or ConcurrentHashMap at Java Controllers?, etc. But I need to understand on doubts. few links/blogs to a good explanation will work for me. Thanks