• Java | JDK8下的ConcurrentHashMap#get


     1  public V get(Object key) {
     2         Node<K,V>[] tab; Node<K,V> e, p; int n, eh; K ek;
     3          //寻址
     4         int h = spread(key.hashCode());
     5         if ((tab = table) != null && (n = tab.length) > 0 &&
     6             (e = tabAt(tab, (n - 1) & h)) != null) {
     7             //当头节点的hash值与key的hash值相同时,判断key的内容知否相同
     8             if ((eh = e.hash) == h) {
     9                 if ((ek = e.key) == key || (ek != null && key.equals(ek)))
    10                     return e.val;
    11             }
    12             //如果头节点的hash值eh<0 红黑树存储 直接寻找
    13             else if (eh < 0)
    14                 return (p = e.find(h, key)) != null ? p.val : null;
    15             //链表查找
    16             while ((e = e.next) != null) {
    17                 if (e.hash == h &&
    18                     ((ek = e.key) == key || (ek != null && key.equals(ek))))
    19                     return e.val;
    20             }
    21         }
    22         return null;
    23     }
  • 相关阅读:
    QuartzQuartz定时任务
    jdbc模糊查询、分页查询、联合查询
    PreparedStatement
    web服务器简述
    JDBC基本操作
    RMI
    Http编程
    2020毕业季业务开发宝典
    程序设计流程图
    系统概要框图
  • 原文地址:https://www.cnblogs.com/jj81/p/11480056.html
Copyright © 2020-2023  润新知