一直想让子线程跑起来后将结果传递给主线程,在对Runable失望后,最终找到了Callable和Future这两个接口,完美知足了个人需求。 最大的区别就是Runable返回void,而Callable返回V或者异常。线程
JDK中描述以下:orm
A task returns a result and may throw an exception. Implementors define a single method with no arguments called call.接口
The Callable interface is simillar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception.it
The Executors class contains utility methods to convert from other common forms to Callable classes.io