kgashok / orientations

Orienting students with the "lay of the land" for each semester subject
3 stars 2 forks source link

Diving deep into Java #31

Open kgashok opened 7 years ago

kgashok commented 7 years ago

HashMap

http://j.mp/hashMapJava

Most of you will agree that HashMap is most favorite topic for discussion in interviews now-a-days. I have gone through several discussions with my colleagues time to time and it really helped. Now, I am continuing this discussion with you all.

I am assuming that if you are interested in internal working of HashMap, you already know basics of HashMap, so i am skipping that part. But if you are new to concept, follow official java docs.

Before moving forward, i will highly recommend reading my previous post : Working with hashCode and equals methods in java

ConcurrentHashMap

http://j.mp/concurrentHashmapJava

It allows concurrent access to the map. Part of the map called Segment (internal data structure) is only getting locked while adding or updating the map. So ConcurrentHashMap allows concurrent threads to read the value without locking at all. This data structure was introduced to improve performance.

Concurrency-Level: Defines the number which is an estimated number of concurrently updating threads. The implementation performs internal sizing to try to accommodate this many threads.