解析 Callable Runnable Future 使用和原理
概念 Callable类的定义 @FunctionalInterface public interface Callable<V> { V call() throws Exception; } Runnable类的定义 @FunctionalInterface public interface Runnable { public abstract void run(); } Future类的定义 public interface Future<V> { boolean cancel(boolean mayInterruptIfRunning); boolean isCancelled(); boolean isDone(); V get() throws InterruptedException, ExecutionException; V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException; } Callable Runnable Future 都是为异步执行设计的接口类。Callable与Runnable接口的区别是Callable有返回值,并且会抛出异常信息,Runnable没有返回值,也不允许抛出异常