在下面给出的代码中,i.intValue
正在抛出NPE
. 但它没有打印出来。相反,ScheduledExecutorService
通过取消后续执行来静默终止。为什么?
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.*;
class Concurr
{
public static void main(String[] args)
{
ScheduledExecutorService sce = Executors.newScheduledThreadPool(1);
Runnable task = new Runnable()
{
public void run()
{
System.out.print(".");
Integer i = null;
i.intValue();
}
};
final ScheduledFuture<?> future = sce.scheduleAtFixedRate(task,0,2,TimeUnit.SECONDS);
sce.schedule( new Runnable()
{
public void run()
{
future.cancel(true);
}
},10,TimeUnit.SECONDS);
}
}