How does java ConcurrentHashMap handles concurrency




Asked on March 26, 2014
HI All,
How does  java ConcurrentHashMap  handles concurrency internally?

Thanks



Replied on April 02, 2014

ConcurrentHashMap implements   Segment class.  Segment class behaves like a  hashtable and  is synchronized using RetrantLock. Retrieval of content from ConcurrentHashMap does  not implement locking. But it returns the most updated value. While putting value in ConcurrentHashMap,  it follows the below steps.


1. Check for null value, if null throw exception.

2. Create hash code

3. Get the segment table for the hashcode

4. Put the value




Write Answer











©2024 concretepage.com | Privacy Policy | Contact Us