ConcurrentHashMap 和 Collections.synchronizedMap(map) 比较
来源:互联网 发布:javascript好的书籍 编辑:程序博客网 时间:2024/05/16 15:39
如果你有一个 Map 将会被几个线程同时修改, 那么在Java API 中 你有三种不同的同步 Map 实现可以选择:
Hashtable
Collections.synchronizedMap(map)
ConcurrentHashMap
选择多了也是一种困扰:) 首先,你可以抛开 Hashtable 了,这是一个旧的实现(继承自废弃的 Dictioanry 类),当它被用于 synchronized 时,会有严重的扩展性危机,现在已经不鼓励在新的项目中使用它了。
下面讨论剩下的两种。根据需求, ConcurrentHashMap 更适合。它允许在不 阻塞线程 (block threads)的情况下,几个线程同时修改Map。
Collections.synchronizedMap(map) 创建一个阻塞Map (blocking map), 这会降低map性能。如果需要确保数据的 一致性,使得每个线程都有Map 的即时视图,那么可以使用它。
“Use the first if performance is critical, and each thread only inserts data to the map, with read happening less frequently. Use teh seconc option if you need to ensure data consistency, and each thread needs to hava an up-to-date view of the map.”
- ConcurrentHashMap 和 Collections.synchronizedMap(map) 比较
- 集合类Map ConcurrentHashMap Collections.synchronizedMap()
- ConcurrentHashMap Collections.synchronizedMap和Hashtable讨论
- ConcurrentHashMap Collections.synchronizedMap和Hashtable讨论
- ConcurrentHashMap Collections.synchronizedMap和Hashtable讨论
- HashMap和SynchronizedMap和ConcurrentHashMap性能比较
- Hashtable 和 HashMap和concurrentHashMap和collections.synchronizedMap
- Collections.synchronizedMap()、ConcurrentHashMap、Hashtable之间的区别 为什么要比较Hashtable、SynchronizedMap()、Co
- ConcurrentHashMap、Collections.synchronizedMap、Hashtable讨论
- HashMap、 HashTable 、Collections.synchronizedMap、 ConcurrentHashMap
- Hashtable、synchronizedMap、ConcurrentHashMap 比较
- Hashtable、synchronizedMap、ConcurrentHashMap 比较
- Hashtable、synchronizedMap、ConcurrentHashMap 比较
- Hashtable、synchronizedMap、ConcurrentHashMap 比较
- Hashtable、synchronizedMap、ConcurrentHashMap 比较
- Hashtable、synchronizedMap、ConcurrentHashMap 比较
- Hashtable、synchronizedMap、ConcurrentHashMap 比较
- Hashtable、synchronizedMap、ConcurrentHashMap 比较
- Hibernate的事务处理机制
- C++中的模板
- 常见FC,SAS,SATA接口硬盘的区别
- 原生JS实现淡入淡出效果(fadeIn/fadeOut/fadeTo)
- 组播
- ConcurrentHashMap 和 Collections.synchronizedMap(map) 比较
- 【Excel实用操作灵活技术九则】
- iOS系统GCD学习(6):Dispatch Sources
- Connectivity in a directed graph
- 指针的值
- c++builder字符串转换为日期的通用函数
- Android开发之json解析案例详解==++
- Com Explorer 2.0 注册算法大概分析
- bubbleSort