1、future
提前完成任務(wù),處理其他業(yè)務(wù),等待線程結(jié)果
public class Demo {
public static void main(String[] args) throws Exception {
Callable<Integer> callable = () -> {
System.out.println("進(jìn)入callable");
TimeUnit.SECONDS.sleep(4);
return 1;
};
FutureTask<Integer> task = new FutureTask<>(callable);
Thread thread = new Thread(task);
thread.start();
System.out.println("處理其他業(yè)務(wù) " );
Integer integer = task.get();
System.out.println("等待線程執(zhí)行的結(jié)果: " + integer);
}
}