`
liuzhaomin
  • 浏览: 199582 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

FutureTask&Sync innerRun

阅读更多

 

/**
         * The thread running task. When nulled after set/cancel, this
         * indicates that the results are accessible.  Must be
         * volatile, to ensure visibility upon completion.
         */
        private volatile Thread runner;

void innerRun() {
            if (!compareAndSetState(0, RUNNING))    //设置失败,直接返回;成功,继续
                return;
            try {
                runner = Thread.currentThread();
                if (getState() == RUNNING) // recheck after setting thread
                    innerSet(callable.call());
                else
                    releaseShared(0); // cancel
            } catch (Throwable ex) {
                innerSetException(ex);
            }
        }
 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics