java并发包之Callable
Callable和Runnable的差异
Callable接口类似于Runnable,但是Runnable不会返回结果,并且无法抛出返回结果的异常,而Callable可以
package com.wjz.demo; import java.util.concurrent.Callable; public class CallableDemo { public static void main(String[] args) { try { Callable<String> call = new Callable<String>() { @Override public String call() throws Exception { return "hello world!"; } }; System.out.println(call.call()); Runnable run = new Runnable() { @Override public void run() { System.out.println("hello world!"); } }; run.run(); } catch (Exception e) { // } } }