===
package leetcode0606.JUC.ConcurrentHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
public class _addCount {
addCount(1L, binCount);
private final void addCount(long x, int check) {
/*
check
>=1 当前桶位 链表的长度 或者 发生冲突的位置
=0 当前桶位的 头节点为null
2 当前桶位为红黑树
*/
/*
LongAdder
*/
// s 当前map.table中的元素数量
// b 表示 LongAdder 中的base值
// as 表示cells数组
ConcurrentHashMap.CounterCell[] as; long b, s;
/*
条件一: as = counterCells) != null
true 表示cells数组已经初始化,当前线程使用hash去寻址找到合适的cell,去累加数据
false 走一下个跳进
=====================================================================================================
条件二: !U.compareAndSwapLong(this, BASECOUNT, b = baseCount, s = b + x)
true 说明cells数组未初始化,该线程只能去写basecount,结果失败了,即与其它线程发生了冲突,当前线程尝试去创建cells数组
false 说明写basecount成功,不需要创建cells数组,直接退出。
*/
if ((as = counterCells) != null ||
!U.compareAndSwapLong(this, BASECOUNT, b = bas