Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Segment class in ConcurrentHashMap usage

Looking into implementation of ConcurrentHashMap, I see that when trying to manipulate it(put/remove), value is found and this value is then used as lock for synchronized code which performs actual manipulation. This way only that bucket is locked where value actually exists.

I also see a class Segment declared and in many resources available online its mentioned that this is used to implement concurrency. But I couldn’t find any code in implementation using Segment for synchronization implementation.

So what actually I miss here?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am looking into java 11.

>Solution :

Looking at the sources of OpenJDK 8, the class Segment bears a comment:

    /**
     * Stripped-down version of helper class used in previous version,
     * declared for the sake of serialization compatibility
     */
    static class Segment<K,V> extends ReentrantLock implements Serializable {
        ...
    }

So it seems to be present only for backwards-compatibility.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading