Java ConcurrentHashMap is better than HashMap performance wise?

前端 未结 4 884
半阙折子戏
半阙折子戏 2020-12-08 10:52

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

4条回答
  •  难免孤独
    2020-12-08 11:05

    If you are accessing the HashMap with only a single thread HashMap is fastest (it does not do any synchronization), if you are accessing it from multiple threads ConcurrentHashMap is faster than doing the synchronization coarse-grained by hand. See here for a little comparison:

    http://www.codercorp.com/blog/java/why-concurrenthashmap-is-better-than-hashtable-and-just-as-good-hashmap.html

提交回复
热议问题