概念
简单使用
在java的源码里 使用callable需要使用FutureTask
做为适配器
public class CallableTest {
public static void main(String[] args) throws ExecutionException, InterruptedException {
MyThread myThread=new MyThread();
FutureTask futureTask=new FutureTask(myThread);
new Thread(futureTask).start();
//获取返回的值
String o = (String) futureTask.get();
System.out.println(o);
}
}
class MyThread implements Callable<String>{
@Override
public String call() throws Exception {
System.out.println("call");
return "hhh";
}
}