带返回值的线程

最后都变了- 提交于 2020-03-05 07:13:36
package com.atguigu.bigdata.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author tianmin
 * @date 2020/3/2 0002
 * @notes
 */
public class CallableTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> futureTask = new FutureTask<>(new MyThread());
        new Thread(futureTask, "A").start();

        Integer result = futureTask.get();
        System.out.println("结果:" + result);
    }
}


class MyThread implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        System.out.println("*******come in call() method*****");
        System.out.println(Thread.currentThread().getName());
        return 1024;
    }
}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!