美文网首页
ConcurrentHashMap实现原理

ConcurrentHashMap实现原理

作者: Top2_头秃 | 来源:发表于2019-06-04 20:47 被阅读0次
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;
        }
    }

相关文章

网友评论

      本文标题:ConcurrentHashMap实现原理

      本文链接:https://www.haomeiwen.com/subject/hxorxctx.html