public class Main {
public static class MyCallable implements Callable<Integer>{
public Integer call() throws Exception {
return 1;
}
}
public static void main(String[] args) {
MyCallable callable=new MyCallable();
FutureTask<Integer> task=new FutureTask<Integer>(callable);
Thread t=new Thread(task);
try {
t.start();
System.out.println(task.get());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
操作系统分配线程执行权是随机的。那么有没有可能出现先执行了`System.out.println(task.get());`的情况。主线程依赖这个工作线程的值。那么会不会出现先执行了主线程呢?
答案地址