ConcurrentHashMap实现原理

2019-06-04  本文已影响0人  Top2_头秃
ConcurrentHashMap在1.7中的实现
ConcuurentHashMap在1.8中的实现结构示意图

java8中,每一个kv对被包装成一个Node节点,Node类是ConcurrenHashMap的内部类,核心代码如下

    static class Node<K,V> implements Map.Entry<K,V> {
        final int hash; // key的hash值
        final K key; // key
        volatile V val; // value
        volatile Node<K,V> next; //指向下一个Node节点

        Node(int hash, K key, V val, Node<K,V> next) {
            this.hash = hash;
            this.key = key;
            this.val = val;
            this.next = next;
        }
    }
上一篇 下一篇

猜你喜欢

热点阅读