并发容器ConcurrentHashMap( 五 )

<< RESIZE_STAMP_SHIFT)return;finishing = advance = true;//最后退出的线程要重新check下是否全部迁移完毕i = n; // recheck before commit}}else if ((f = tabAt(tab, i)) == null)advance = casTabAt(tab, i, null, fwd);else if ((fh = f.hash) == MOVED)advance = true; // already processed//迁移node节点else {synchronized (f) {if (tabAt(tab, i) == f) {Node ln, hn;//链表迁移if (fh >= 0) {int runBit = fhNode lastRun = f;for (Node p = f.next; p != null; p = p.next) {int b = p.hashif (b != runBit) {runBit = b;lastRun = p;}}if (runBit == 0) {ln = lastRun;hn = null;}else {hn = lastRun;ln = null;}//将node链表 , 分成2个新的node链表for (Node p = f; p != lastRun; p = p.next) {int ph = p.hash; K pk = p.key; V pv = p.val;if ((phelsehn = new Node(ph, pk, pv, hn);}//将新node链表赋给nextTabsetTabAt(nextTab, i, ln);setTabAt(nextTab, i + n, hn);setTabAt(tab, i, fwd);advance = true;}//红黑树迁移else if (f instanceof TreeBin) {TreeBin t = (TreeBin)f;TreeNode lo = null, loTail = null;TreeNode hi = null, hiTail = null;int lc = 0, hc = 0;for (Node e = t.first; e != null; e = e.next) {int h = e.hash;TreeNode p = new TreeNode(h, e.key, e.val, null, null);if ((helseloTail.next = p;loTail = p;++lc;}else {if ((p.prev = hiTail) == null)hi = p;elsehiTail.next = p;hiTail = p;++hc;}}ln = (lc <= UNTREEIFY_THRESHOLD) ? untreeify(lo) :(hc != 0) ? new TreeBin(lo) : t;hn = (hc <= UNTREEIFY_THRESHOLD) ? untreeify(hi) :(lc != 0) ? new TreeBin(hi) : t;setTabAt(nextTab, i, ln);setTabAt(nextTab, i + n, hn);setTabAt(tab, i, fwd);advance = true;}}}}}}作者:故人
出处:
突击并发编程JUC系列演示代码地址:


推荐阅读