欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ConcurrentHashMap与一般HashMap的区别 ConcurrentHashMapjava 

程序员文章站 2022-04-20 14:47:52
...
官方文档描述如下:A hash table supporting full concurrency of retrievals and adjustable expected concurrency for updates. This class obeys the same functional specification as Hashtable, and includes versions of methods corresponding to each method of Hashtable. However, even though all operations are thread-safe, retrieval operations do not entail locking, and there is not any support for locking the entire table in a way that prevents all access. This class is fully interoperable with Hashtable in programs that rely on its thread safety but not on its synchronization details. 通俗来说就是:有操作都是线程安全的,但检索操作不必锁定,并且不 支持以某种防止所有访问的方式锁定整个表。此类可以通过程序完全与 Hashtable 进行互操作,这取决于其线程安全,而与其同步细节无关,它的锁机制采用1.5的Lock,而不像HashTable synchronized,性能上好多了,之前用到HashMap而现在有线程安全的需求这是个不错的方案具体可以参考http://blog.csdn.net/xuefeng0707/article/details/40834595