Java - Difference between ConcurrentHashMap, Hashtable and Synchronized Map
来源:互联网 发布:中控网络指纹考勤机 编辑:程序博客网 时间:2024/05/24 05:13
http://javarevisited.blogspot.de/2011/04/difference-between-concurrenthashmap.html
Because sometimes I can't open this page without proper proxy configuration, so I have to copy some content here.
Though all three collection classes are thread-safe and can be used in multi-threaded, concurrent Java application, there is significant difference between them, which arise from the fact that how they achieve their thread-safety.
Hashtable is a legacy class from JDK 1.1 itself, which uses synchronized methods to achieve thread-safety. All methods of Hashtable are synchronized which makes them quite slow due to contention if number of thread increases.
Synchronized Map is also not very different than Hashtable and provides similar performance in concurrent Java programs. Only difference between Hashtable and Synchronized Map is that later is not a legacy and you can wrap any Map to create it's synchronized version by using Collections.synchronizedMap() method.
ConcurrentHashMap is especially designed for concurrent use i.e. more than one thread. By default it simultaneously allows 16 threads to read and write from Map without any external synchronization. It is also very scalable because of stripped locking technique used in internal implementation of ConcurrentHashMap class. Unlike Hashtable and Synchronized Map, it never locks whole Map, instead it divides the map in segments and locking is done on those. It perform better if number of reader threads is greater than number of writer threads.
In Summary ConcurrentHashMap only locked certain portion of Map while Hashtable lock full map while doing iteration.
ConcurrentHashMap do not allow null keys or null values while synchronized HashMap allows one null keys.
- Java - Difference between ConcurrentHashMap, Hashtable and Synchronized Map
- Difference between ConcurrentHashMap and Collections.synchronizedMap and Hashtable in Java
- Difference between ConcurrentHashMap and Collections.synchronizedMap and Hashtable in Java
- Difference between HashMap and Hashtable in Java
- Difference between HashMap and HashTable? Can we make hashmap synchronized?
- 【Java 源码技术】--Difference between HashMap and ConcurrentHashMap(165)
- difference between Lock and synchronized
- Java - What is difference between HashMap and Hashtable?
- What is difference between HashMap and Hashtable in Java?
- 6 Difference Between HashMap And HashTable
- Difference between Set, List and Map in Java - Interview question
- HashMap,Hashtable,ConcurrentHashMap和synchronized Map
- java实现同步map的几种方法(lock,synchronized,rwlock,ConcurrentHashMap,hashtable,SynchronizedMap)
- Difference between synchronized and reentrantlock? Pros and Cons [closed]
- What's the difference between hashtable and maps?
- HashMap,Hashtable,ConcurrentHashMap 和 synchronized Map 的原理和区别
- HashMap,Hashtable,ConcurrentHashMap 和 synchronized Map 的原理和区别
- [Java]Difference between String StringBuffer and StringBuilder
- 调用High-speed Charting Control图表VC6.0中该怎么设置
- Jmeter性能测试内部分享
- Xcode工程使用CocoaPods管理第三方库新建工程时出现错误
- Ubuntu学习过程中的问题及解决
- 深入理解java嵌套类和内部类
- Java - Difference between ConcurrentHashMap, Hashtable and Synchronized Map
- QPixmap和QImage的区别及剖析
- [RFID]射频卡介绍(三)ID-T5557
- PostgrelSql 9.4 hot standby配置
- 在IOS APP中添加自定义的Framework
- 深入分析C#键盘勾子(Hook)拦截器,屏蔽键盘活动的详解【方便自己学习查阅】
- CUDA系列学习(一)An Introduction to GPU and CUDA
- HTTP错误汇总(404、302、200……)
- 虚拟主机多端口的配置