HashMap,HashTable和ConcurrentHashMap的区别
来源:互联网 发布:ubuntu hadoop 2.6 编辑:程序博客网 时间:2024/05/16 09:50
一、HashMap与HashTable的区别:
1.HashMap是非线程安全的,HashTable是线程安全的,HashTable中的很多方法都是加了sysnchronized关键字的,确保了方法的同步;
2.HashMap可以接受空key和value,而HashTable不能接受空key和value;
3.由于HashMap是异步执行,而HashTable是同步执行,所以在单线程环境下,HashMap的速度高于HashTable;
4.HashMap的迭代器采用的是Iterator,Iterator是快速失败(Fail-Fast),在遍历过程中若有其他线程对该HashMap进行增加或者删除元素,则会抛出ConcurrentModificationException,因为快速失败的迭代器是操作的集合本身,
HashTable的迭代器是Enumeration,Enumeration是安全失败(Fail-Safe),在遍历过程中若有其他线程对该集合进行增加或则删除元素,不会抛出ConcurentModificationException,因为安全失败的迭代器操作的是原集合的一个拷贝。
二、HashTable和ConcurrentHashMap的区别:
在进行迭代时,HashTable会锁住整个Map,而ConcurrentHashMap只锁住Map的一部分,所以ConcurrentHashMap在多线程环境下的性能更好。
三、如何让HashMap实现同步功能?
Map m = Collections.synchronizeMap(hashMap);
阅读全文
0 0
- HashTable和HashMap和ConcurrentHashMap的区别
- HashMap HashTable和ConcurrentHashMap的区别
- HashMap HashTable和ConcurrentHashMap的区别
- HashMap、HashTable和ConcurrentHashMap的区别
- HashMap和Hashtable以及ConcurrentHashMap的区别
- HashMap,HashTable和ConcurrentHashMap的区别
- HashMap和HashTable的区别,HashTable和ConcurrentHashMap的区别
- hashmap hashtable concurrenthashmap的区别
- HashMap,:HashTable,ConcurrenthashMap的区别
- HashMap,Hashtable,ConcurrentHashMap 和 synchronized Map 的原理和区别
- HashMap,Hashtable,ConcurrentHashMap 和 synchronized Map 的原理和区别
- HashMap 和 Hashtable ,ConcurrentHashMap三者的区别
- JAVA基础(35) HashMap HashTable和ConcurrentHashMap的区别
- HashMap的扩容机制, ConcurrentHashMap和Hashtable主要区别
- ConcurrentHashMap、HashMap、HashTable区别
- hashMap ,hashTable ,concurrentHashMap区别
- HashMap HashTable ConcurrentHashMap区别
- HashMap HashTable ConcurrentHashMap 区别
- 3秒钟不懂你砍我:一行代码解决ListView,GridView的一切
- java 笔试常考零碎知识点
- Find a way -从两个点分别bfs
- JAVA多维Map
- 头疼,技术氛围究竟怎么来
- HashMap,HashTable和ConcurrentHashMap的区别
- PHP攻城狮培养计划-PHP进阶:面向对象及TP5框架初识
- Installing TensorFlow on Ubuntu 1.3
- 图像处理技术上的空间域和空间频率域
- linux性能调优命令
- 从GoogLeNet架构到deep dream模型
- Unity3d 简单的Avatar换装系统
- 文章标题
- oracle分页案例