码迷,mamicode.com
首页 > 编程语言 > 详细

java编程-无锁初始化

时间:2017-03-25 16:42:04      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:nod   private   com   warnings   try   ret   code   table   编程   

private final Node<K,V>[] initTable() {
        Node<K,V>[] tab; int sc;
        while ((tab = table) == null || tab.length == 0) {
            if ((sc = sizeCtl) < 0)
                Thread.yield(); // lost initialization race; just spin
            else if (U.compareAndSwapInt(this, SIZECTL, sc, -1)) {
                try {
                    if ((tab = table) == null || tab.length == 0) {
                        int n = (sc > 0) ? sc : DEFAULT_CAPACITY;
                        @SuppressWarnings("unchecked")
                        Node<K,V>[] nt = (Node<K,V>[])new Node<?,?>[n];
                        table = tab = nt;
                        sc = n - (n >>> 2);
                    }
                } finally {
                    sizeCtl = sc;
                }
                break;
            }
        }
        return tab;
    }

 

java编程-无锁初始化

标签:nod   private   com   warnings   try   ret   code   table   编程   

原文地址:http://www.cnblogs.com/youge-OneSQL/p/6617333.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!