HashMap+ConcurrentHashMap+HashTable
来源:互联网 发布:红蜘蛛软件年费 编辑:程序博客网 时间:2024/06/08 16:53
1.HashMap
hashmap是一个“链表散列”的数据结构,即数组和链表的结合体。
hashmap是线程不安全的,再多线程环境下使用hashmap进行put操作会引起死循环,导致CPU利用率接近100%,因此在并发情况下不能使用hashmap
2.HashTable
HashTable容器使用synchronized来保证线程安全,但在线程竞争激烈的情况下HashTable的效率非常低下。因为当一个线程访问HashTable的同步方法时,其他线程访问HashTable的同步方法时,可能会进入阻塞或轮询状态。如线程1使用put进行添加元素,线程2不但不能使用put方法添加元素,并且也不能使用get方法来获取元素,所以竞争越激烈效率越低。
3.ConcurrentHashMap
一个ConcurrentHashMap 由多个segment 组成,每个segment 包含一个Entity 的数组。这里比HashMap 多了一个segment 类。该类继承了ReentrantLock 类,所以本身是一个锁。当多线程对ConcurrentHashMap 操作时,不是完全锁住map, 而是锁住相应的segment 。这样提高了并发效率。[首先将数据分成一段一段的存储,然后给每一段数据配一把锁,当一个线程占用锁访问其中一个段数据的时候,其他段的数据也能被其他线程访问。]
1、ConcurrentHashMap是由Segment数组结构组成。
2、Segment是由HashEntry数组结构组成,并且Segment本身继承了可重入锁ReentrantLock,在ConcurrentHashMap里扮演锁的角色。
3、HashEntry是真正用于存储键值对数据的地方,HashEntry是一个链表结构。
- HashMap,HashTable,ConcurrentHashMap,ConcurrentSkipListMap
- HashMap、ConcurrentHashMap、HashTable、HashSet
- ConcurrentHashMap、HashMap、HashTable区别
- HashMap、HashTable、ConcurrentHashMap、Queue
- HashMap HashTable ConcurrentHashmap
- hashMap ,hashTable ,concurrentHashMap区别
- HashMap、HashTable、ConcurrentHashMap
- HashMap HashTable ConcurrentHashMap区别
- HashMap HashTable和ConcurrentHashMap
- Hashtable,HashMap,ConcurrentHashMap
- HashMap HashTable ConCurrentHashMap
- hashmap 、hashtable、 ConcurrentHashMap总结
- HashTable/HashMap/ConcurrentHashMap
- HashMap、HashTable、ConcurrentHashMap
- HashMap、Hashtable与ConcurrentHashMap
- HashMap+ConcurrentHashMap+HashTable
- HashMap HashTable ConcurrentHashMap 区别
- hashmap、hashtable、ConCurrentHashMap分析
- qt tcp/ip协议简单的用户图书管理系统(若有错误,请提醒,谢谢)
- Docker 中 安装Linux镜像
- 折半查找
- c#代码规范
- 【Leetcode】33. Search in Rotated Sorted Array
- HashMap+ConcurrentHashMap+HashTable
- [[][[]]+[]][+[]][++[+[]][+[]]] is "n" in javascript
- 如何使用Burp Suite Macros绕过防护进行自动化fuzz测试
- Oracle 创建表的存储过程
- Android中的WIFI模块开发思路
- Python时间序列LSTM预测系列教程(3)-单变量
- : java.net.SocketTimeoutException: connect timed out
- PowerDesigner逆向工程导入MYSQL数据库总结
- oh-my-zsh 强大漂亮的shell命令