Java 未来任务货币设计
在Java 未来任务货币设计,java,concurrency,java.util.concurrent,Java,Concurrency,Java.util.concurrent,在java.util.concurrent.FutureTask#run public void run() { if (state != NEW || !UNSAFE.compareAndSwapObject(this, runnerOffset, null, Thread.currentThread())) return; try { Callable&l
java.util.concurrent.FutureTask#run
public void run() {
if (state != NEW ||
!UNSAFE.compareAndSwapObject(this, runnerOffset,
null, Thread.currentThread()))
return;
try {
Callable<V> c = callable;
if (c != null && state == NEW) {
V result;
boolean ran;
try {
result = c.call();
ran = true;
} catch (Throwable ex) {
result = null;
ran = false;
setException(ex);
}
if (ran)
set(result);
}
} finally {
// runner must be non-null until state is settled to
// prevent concurrent calls to run()
runner = null;
// state must be re-read after nulling runner to prevent
// leaked interrupts
int s = state;
if (s >= INTERRUPTING)
handlePossibleCancellationInterrupt(s);
} }
public void run(){
如果(状态)=新||
!不安全。比较AndSwapObject(此、runnerOffset、,
null,Thread.currentThread())
返回;
试一试{
可调用c=可调用;
如果(c!=null&&state==NEW){
V结果;
布尔ran;
试一试{
结果=c.call();
ran=真;
}捕获(可丢弃的ex){
结果=空;
ran=假;
setException(ex);
}
如果(运行)
设置(结果);
}
}最后{
//在将状态设置为之前,运行程序必须为非null
//防止对run()的并发调用
runner=null;
//将运行程序置零后必须重新读取状态以防止
//泄漏中断
int s=状态;
如果(s>=中断)
HandlePossibleConcellationInterrupt(多个);
} }
最后阻止评论是什么意思
谢谢大家! 我添加了这个类,你可以阅读idk 1.8Ah的源代码谢谢,我没有注意到这是JDK的未来任务。我不确定,但我想知道这是否是评论中的一个输入错误,它们的真正意思是“为了防止并发调用cancel()”。我添加了这个类,你可以阅读idk 1.8Ah的源代码谢谢,我没有注意到这是JDK的未来任务。我不确定,但我想知道这是否是评论中的输入错误,它们的真正意思是“防止并发调用cancel()