码迷,mamicode.com
首页 > 其他好文 > 详细

HashMap HashTable ConcurrentHashMap 简单比较

时间:2014-07-27 12:11:27      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:java   hashmap   concurrenthashmap   

1. HashMap HashTable ConcurrentHashMap都是java哈希算法的实现,其中HashMap是非线程安全的,HashTable 和ConcurrentHashMap是线程安全的。单线程环境下HashMap更有速度优势。

2. HashTable 的实现方式比较简单粗暴,直接对修改操作进行加锁来控制并发访问。

3. ConcurrentHashMap,通过分段(segment)来提高并发性能,进行修改操作时,只是对相应的段进行加锁,理论上段个数的线程可以并行访问ConcurrentHashMap。另外对与size等操作,ConcurrentHashMap借用了乐观锁的实现,理论上可以做到不加锁。

HashMap HashTable ConcurrentHashMap 简单比较

标签:java   hashmap   concurrenthashmap   

原文地址:http://houenxun.blog.51cto.com/3958763/1530337

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!