package com.cxy.juc; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; class MyThread implements Callable<Integer> { @Override public Integer call() throws Exception { return 1024; } } public class CallableDemo { public static void main(String[] args) throws ExecutionException, InterruptedException { FutureTask<Integer> futureTask =new FutureTask(new MyThread()); new Thread(futureTask,"a").start(); Integer reslut =futureTask.get(); System.out.println(reslut); } }
原文地址:https://www.cnblogs.com/xiufengchen/p/11665813.html
时间: 2024-10-11 08:06:47