Runnable与Callable
Runnable没有参数和返回值;Callable有返回值。
Future
Future保存异步计算的结果。可以启动一个计算,将Future对象交给某个线程执行。调用Future对象的get方法会被阻塞知道计算完成。
FutureTask包装器时一种非常便利的机制,可以将Callable转换成Future和Runnable。例:
Callable<Integer> myComputation = . . . ;
FutureTask<Integer> task = new FutureTask<Integer>(myComputation);
Thread t = new Thread(task); // as Runnable
t.start();
. . .
Integer res = task.get(); // as Future