import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
public class CallableDemo {
public static void main(String[] args) throws ExecutionException, InterruptedException {
Callable<String> callable=new Callable<String>(){
@Override
public String call() throws Exception {
return "返回值="+new Random().nextInt(200);
}
};
FutureTask<String> futureTask =new FutureTask<>(callable);
new Thread(futureTask).start();
String result=futureTask.get();
System.out.println(result);
}
}
版权声明:本文为xinpz原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。