ConcurrentHashMap实现原理

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;
        }
    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容