源码解析
会写代码的考研小哥
十年磨一剑,莫欺少年穷
展开
-
ConcurrentHashMap 源码解析(四):put()方法超硬核源码解析
ConcurrentHashMap中的put()方法是其中一个比较复杂的方法,其中涉及到了很多的知识点。比如,迁移时的多线程协助、桶位树化、多线程累加等等。下面我将详细解析put()方法和所涉及到的所有子方法的源码。put()方法中其实是调用了putVal()来实现的。/** * Maps the specified key to the specified value in this table. * Neither the key nor the value can be null..原创 2020-05-20 17:09:37 · 331 阅读 · 2 评论 -
ConcurrentHashMap 源码解析(三):get()
本文重点解析ConcurrentHashMap.get()方法,及其代码中包含的所有涉及到的子方法。其中,spread()和find()是比较复杂的两个方法,下面会重点讲解。/** * Returns the value to which the specified key is mapped, * or {@code null} if this map contains no mapping for the key. * * <p>More formally, if th.原创 2020-05-19 15:50:22 · 235 阅读 · 0 评论 -
ConcurrentHashMap 源码解析(二):ConcurrentHashMap初始化
ConcurrentHashMap有5种初始化方法。其中,ConcurrentHashMap()是个无参构造,里面没有任何代码,不需要理会;ConcurrentHashMap(int initialCapacity, float loadFactor)是个套娃的方法,只需要理解ConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)就可以了。因此下面就详细解析剩下的3种初始化方法。1、Concurren.原创 2020-05-18 18:17:55 · 1179 阅读 · 0 评论 -
ConcurrentHashMap 源码解析(一):解析定义的常量
在解析ConcurrentHashMap源码之前首先需要先弄懂这些常量的定义,这将会对接下来看源码有很大的帮助。这里要注意一点,ConcurrentHashMap1.8中会保留1.7的常量,但是并不会参与到1.8的逻辑计算中。/** * The largest possible table capacity. This value must be * exactly 1<<30 to stay within Java array allocation and indexing .原创 2020-05-18 14:53:12 · 163 阅读 · 0 评论 -
面试必备--手撕HashMap源码
HashMap也是面试官最喜欢问的知识点之一。那么接下来我为大家分析下HashMap中的常用方法原创 2020-05-06 10:34:25 · 215 阅读 · 0 评论 -
面试必问--手撕FutureTask源码
FutureTask作为面试必问的知识,重要性可想而知。因此,下面给大家逐条分析Doug Lea大神的源码。首先是介绍下FutureTask类中的变量//表示当前task的状态 private volatile int state; //表示当前task尚未执行 //场景:1、任务刚新建还未入队列 // 2、任务刚新建已入队列,还未被线程执行 /...原创 2020-04-28 21:16:33 · 216 阅读 · 0 评论 -
手撕LongAdder-add()源码
/** * Adds the given value. * * @param x the value to add */ public void add(long x) { //as: 表示cells引用 //b: 表示获取的base值 //v: 表示 期望值 //m: 表示cells数...原创 2020-04-27 15:59:10 · 254 阅读 · 0 评论