FutureTasktask = new FutureTask<>(()-> { Thread.sleep(5000L); log.info(Thread.currentThread().getName()); return Thread.currentThread().getName(); }); Thread t = new Thread(task); t.start(); log.info(task.get());
FutureTask
虽然也可用于任务的异步执行,获取结果, 但是结果不能手动完成,没有封装线程池,没有CompletableFuture
灵活, 基本上是在Executor中使用
Posted in: java基础
Comments are closed.