Sentinel icon indicating copy to clipboard operation
Sentinel copied to clipboard

为什么用非线程安全的HashMap,而不是ConcurrentHashMap?

Open MrSummer33 opened this issue 8 years ago • 3 comments

看源码发现很少直接使用ConcurrentHashMap而是通过 上锁+copyAndWrite 的通过HashMap,来保障线程安全 此处为何不直接使用ConcurrentHashMap? image

MrSummer33 avatar Sep 11 '18 11:09 MrSummer33

The chainMap here will only change at the very beginning of the application's start, then it will be stable. So we use Copy on Write Map to get higher concurrency performance.

CarpenterLee avatar Sep 15 '18 10:09 CarpenterLee

但这个地方,每次chain==null时,不都得加锁判断么?

MoneyHacker avatar Dec 21 '18 09:12 MoneyHacker

The chainMap here will only change at the very beginning of the application's start, then it will be stable. So we use Copy on Write Map to get higher concurrency performance.

是否多此一举?cmap早就不用分段锁了,所以cmap在读上的并发性能和hashmap是一个量级的吧?

jianbo2018 avatar Nov 11 '23 14:11 jianbo2018