1、future
提前完成任务,处理其他业务,等待线程结果
public class Demo {
public static void main(String[] args) throws Exception {
Callable<Integer> callable = () -> {
System.out.println("进入callable");
TimeUnit.SECONDS.sleep(4);
return 1;
};
FutureTask<Integer> task = new FutureTask<>(callable);
Thread thread = new Thread(task);
thread.start();
System.out.println("处理其他业务 " );
Integer integer = task.get();
System.out.println("等待线程执行的结果: " + integer);
}
}