//使用Future 和 Callable
public class MyFuture {
public static void main(String[] args) throws InterruptedException, ExecutionException {
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
Future<String> future = singleThreadExecutor.submit(new MyTask());
MyTask task = new MyTask();
System.out.println(future.get());
}
static class MyTask implements Callable<String>{
@Override
public String call() throws Exception {
System.out.println("hehe");
return "返回值";
}
}
}