代码如下
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
/**
* @author lzq
* @data 2020/4/30 0030 - 下午 4:02
*/
public class Test2 {
public static void main(String[] args) throws ExecutionException, InterruptedException {
MyThread thread=new MyThread();
FutureTask task = new FutureTask(thread);
new Thread(task,"a").start();
new Thread(task,"b").start();
System.out.println(task.get());
}
}
class MyThread implements Callable {
@Override
public String call() {
System.out.println("实现callable");
return "得到返回值";
}
}
执行结果为: