CurrentHashMap - jdk1.7

//採用數組 + 鏈表結構,再對數組元素採用分段鎖
//數組
final Segment<K,V>[] segments;

//數組元素
static final class Segment<K,V> extends ReentrantLock implements Serializable {
transient volatile HashEntry<K,V>[] table;
}

//鏈表
static final class HashEntry<K,V> {
    final int hash;
    final K key;
    volatile V value;
    volatile HashEntry<K,V> next;
}

//構造方法裏concurrencyLevel是Segment[]數組的長度,initialCapacity(CurrentHashMap的容量)是所有HashEntry數組的長度總和,
//即每個Segment對象裏面的HashEntry數組長度爲initialCapacity/concurrencyLevel
//initialCapacity和concurrencyLevel默認值是16,loadFactor默認值是0.75
public ConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel) {}

//CurrentHashMap put元素
//1.先獲取key哈希值,然後根據哈希值定位到Segment[]的index
//2.調用Segment.put()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章