[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/ManCoding/Java-Interview/dev/MD/ConcurrentHashMap.md [Back]  [Original]

# ConcurrentHashMap 

 `HashMap` `*`

 `ConcurrentHashMap` 

## 
![](https://ws2.sinaimg.cn/large/006tNc79ly1fn2f5pgxinj30dw0730t7.jpg)

 `Segment` `HashEntry`  `HashMap` 

`ConcurrentHashMap`  `Segment`  `ReentrantLock` `HashTable`  `put`  `get`  ConcurrentHashMap  `CurrencyLevel` (Segment ) `Segment`  `Segment`

## get 
`ConcurrentHashMap`  `get` 

 `Key`  `Hash`  `Segment`  `Hash`  `HashEntry`  `value`  `volatile` ([volatile ](https://github.com/crossoverJie/Java-Interview/blob/master/MD/Threadcore.md#%E5%8F%AF%E8%A7%81%E6%80%A7))

## put 

 `HashEntry`  
```java
    static final class HashEntry {
        final int hash;
        final K key;
        volatile V value;
        volatile HashEntry next;

        HashEntry(int hash, K key, V value, HashEntry next) {
            this.hash = hash;
            this.key = key;
            this.value = value;
            this.next = next;
        }
    }
```

 HashEntry  value  `volatile`  put 

 Key  Hash  Segment put  HashMap HashMap ()

 ConcurrentHashMap 

## size 

 `Segment`  `volatile`  `count` , `ConcurrentHashMap`  `size`  `count`  `volatile` 

 `size`  `count`  `count`  `size`

 `ConcurrentHashMap`  `Segment`  `modCount`  `put remove` `modCount`  +1 `modCount` 

Web Proxy Viewer  |  New URL  |  Original Page