concurrenthasmap

concur'renthashmap

  • java1.7

    • hashMap在单线程中使用大大提高效率,在多线程的情况下使用hashTable来确保安全。hashTable中使用synchronized关键字来实现安全机制,但是synchronized是对整张hash表进行锁定即让线程独享整张hash表,在安全同时造成了浪费。concurrentHashMap采用分段加锁的机制来确保安全

  • java1.8

    • concurrenthashmap取消了segment分段锁,采用cas和synchronized来保证并发安全,数据结构跟hashmap1.8的结构类似,数组+链表或红黑二叉树

原文地址:https://www.cnblogs.com/albertshine/p/13192871.html