中易网

java concurrenthashmap和hashmap的区别

答案:2  悬赏:30  
解决时间 2021-04-07 11:13
java concurrenthashmap和hashmap的区别
最佳答案
最大的区别就是ConcurrentHashMap是线程安全的,hashMap不是线程安全的。
为什么线程安全呢:
ConcurrentHashMap代码中可以看出,它引入了一个“分段锁”的概念,具体可以理解为把一个大的Map拆分成N个小的HashTable,根据key.hashCode()来决定把key放到哪个HashTable中。
在ConcurrentHashMap中,就是把Map分成了N个Segment,put和get的时候,都是现根据key.hashCode()算出放到哪个Segment中:
全部回答
前者是 a hash table supporting full concurrency of retrievals and adjustable expected concurrency for updates. this class obeys the same functional specification as hashtable, and includes versions of methods corresponding to each method of hashtable. however, even though all operations are thread-safe, retrieval operations do not entail locking, and there is not any support for locking the entire table in a way that prevents all access. this class is fully interoperable with hashtable in programs that rely on its thread safety but not on its synchronization details. 后者是 hash table based implementation of the map interface. this implementation provides all of the optional map operations, and permits null values and the null key. (the hashmap class is roughly equivalent to hashtable, except that it is unsynchronized and permits nulls.) this class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
vivoy18l设置里的自动锁屏为什么不见了
陇海西路169号郑州人才大厦在哪
这是个什么电机,有什么用途
用英语说这么一句话,怎么写?
为什么邮件发出去以后再已发送里面找不到呢?
南坡村卫生院在哪里啊,我有事要去这个地方
58司机端和货拉垃司机端那个接单多
女孩是学平面设计好,还是环境设计
电视剧《夏至未至》什么时候上映 上映时间
芜湖职业技术学院能专升本吗
云南人数最少的少数民族是哪个
大自然的启示卡片
德亚哪个便宜
电气图上thb1-l-40是什么闸
Le烫染工作室怎么去啊,有知道地址的么
推荐资讯
要写 鲁滨逊漂流记 读后感的作文 要定一个精
王者荣耀排位我看有的可以禁英雄,为什么我的
王者荣耀怎么攒钻石快
《新还珠格格》太夸张了,水汪漾噙泪海陆扮演
欣怡美发美容这个地址在什么地方,我要处理点
科目三练车要钱
最近上网的时候发现了一个新词语“铲铲队”,
3Dmax为几何体加线问题。
结婚租车价位大概是多少 婚车租赁有哪些步骤
半半招牌料理地址在什么地方,想过去办事
御龙在天是打造装备好还是改造装备好
双办地址在什么地方,想过去办事
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?