Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6143475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:31:42+00:00 2026-05-23T18:31:42+00:00

I was just reading the book Clean Code and came across this statement: When

  • 0

I was just reading the book Clean Code and came across this statement:

When Java was young Doug Lea wrote the seminal book[8] Concurrent
Programming in Java. Along with the book he developed several
thread-safe collection, which later became part of the JDK in the
java.util.concurrent package. The collections in that package are safe
for multithreaded situations and they perform well. In fact, the
ConcurrentHashMap implementation performs better than HashMap in

nearly all situations. It also allows for simultaneous concurrent
reads and writes, and it has methods supporting common composite
operations that are otherwise not thread safe. If Java 5 is the
deployment environment, start with
ConcurrentHashMap

Note that in the above quote I used “[n]”, where n is some number, to indicate the places where the author provided references, and as you can see he did not provide any reference for the bold part.

Not that I don’t believe this statement, but I would love to know the supporting evidences of this statement. So, does anyone know any resources that shows the performance statistics for both ConcurrentHashMap and HashMap? Or can anyone explain to me why ConcurrentHashMap is faster than HashMap?

I probably will look into ConcurrentHashMap’s implementation at work when I’m taking a break, but for now I would like to hear the answers from fellow SOers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:31:42+00:00Added an answer on May 23, 2026 at 6:31 pm

    Doug Lea is extremely good at these things, so I won’t be surprised if at one time his ConcurrentHashMap performs better than Joshua Bloch’s HashMap. However as of Java 7, the first @author of HashMap has become Doug Lea too. Obviously now there’s no reason HashMap would be any slower than its concurrent cousin.

    Out of curiosity, I did some benchmark anyway. I run it under Java 7. The more entries there are, the closer the performance is. Eventually ConcurrentHashMap is within 3% of HashMap, which is quite remarkable. The bottleneck is really memory access, as the saying goes, "memory is the new disk (and disk is the new tape)". If the entries are in the cache, both will be fast; if the entries don’t fit in cache, both will be slow. In real applications, a map doesn’t have to be big to compete with others for residing in cache. If a map is used often, it’s cached; if not, it’s not cached, and that is the real determining factor, not the implementations (given both are implemented by the same expert)

    public static void main(String[] args)
    {
        for(int i = 0; i<100; i++)
        {
            System.out.println();
    
            int entries = i*100*1000;
            long t0=test( entries, new FakeMap() );
            long t1=test( entries, new HashMap() );
            long t2=test( entries, new ConcurrentHashMap() );
    
            long diff = (t2-t1)*100/(t1-t0);
            System.out.printf("entries=%,d time diff= %d%% %n", entries, diff);
        }
    }
    
    
    static long test(int ENTRIES, Map map)
    {
        long SEED = 0;
        Random random = new Random(SEED);
    
        int RW_RATIO = 10;
    
        long t0 = System.nanoTime();
    
        for(int i=0; i<ENTRIES; i++)
            map.put( random.nextInt(), random.nextInt() );
    
        for(int i=0; i<RW_RATIO; i++)
        {
            random.setSeed(SEED);
            for(int j=0; j<ENTRIES; j++)
            {
                map.get( random.nextInt() );
                random.nextInt();
            }
        }
        long t = System.nanoTime()-t0;
        System.out.printf("%,d ns %s %n", t, map.getClass());
        return t;
    }
    
    
    static class FakeMap implements Map
    {
        public Object get(Object key)
        {
            return null;  
        }
        public Object put(Object key, Object value)
        {
            return null;  
        }
        // etc. etc.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just came across this quote in a book on OOP that I'm reading, A
I was just reading through Learning Python by Mark Lutz and came across this
I'm reading a book about java. It just got to explaining how you create
I'm reading the book Clean Code and am struggling with a concept. When discussing
I just started reading this book Eloquent Ruby and I have reached the chapter
I'm studying Enterprise Patterns and I'm reading this book . I just read chapter
I just started reading a Java book and wondered; which access specifier is the
I just finished reading a book on scala. What strikes me is that every
Just now, I'm reading Josuttis' STL book. As far as I know -- c++
I was just reading this thread and it occurred to me that there is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.