0
点赞
收藏
分享

微信扫一扫

创建有返回值的线程,测试代码 Callable

残北 2022-02-11 阅读 76

创建有返回值的线程,测试代码

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask futureTask = new FutureTask(() -> {
            ThreadUtil.sleep(10, TimeUnit.SECONDS);
            return "我在等待";
        });
        Thread thread = new Thread(futureTask);
        thread.setName("kaka");
        thread.start();

        Object o = futureTask.get();

        System.out.println(o);
        
    }
举报

相关推荐

0 条评论