
ConcurrentHashMap 源码中 initTable()方法为啥要使用临时变量 tab 和 sc ,集合中变量 table 不都是已经 volatile 立即可见的吗,每次都要拷贝到临时变量中有啥具体意义吗? 这样写不行吗? while (table == null || table.length == 0)
/**
1 lihahahayang OP 自己又看了看,方法中进行拷贝主要减少 table 变量的竞争,数据更新都是通过对 table 的 cas 操作完成。 |
2 xxxrubyxxx Jan 12, 2022 |
3 huang119412 Jan 19, 2022 It's a coding style made popular by Doug Lea. It's an extreme optimization that probably isn't necessary; |