package cn.bunny.demo5;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

@Slf4j
public class UdkFuture {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 线程池
        ExecutorService service = Executors.newFixedThreadPool(2);
        // 提交任务
        Future<Integer> future = service.submit(() -> {
            Thread.sleep(1000);
            return 50;
        });

        // 主线程通过 future 来获取结果
        log.debug("主线程等待结果");
        future.get();
        log.debug("结果是：{}", future.get());
    }
}
