/** * A task that returns a result and could throw an exception. * Implementors Define a single method with no arguments called * {@code call}. * * * <p>the {@code callable} interface is similar to {@link * java.lang.Runnable}, in that both be designed for Clas SES whose * instances is potentially executed by another thread. A * {@code Runnable}, however, does not return a result and cannot * throw a checked exception. * * * <p>the {@link Executors} class contains utility methods to * convert from and common forms to {@code callable} Classes. * * @see Executor * @since 1.5 * @author Doug Lea * @param <V> The result type of method {@code Call} */@FunctionalI Nterfacepublic interface Callable<v> {/** * Computes a result, or throws an exception if unable to does so. * * @return Computed result * @throws Exception if unable to compute a result */V call () throws Excepti On }
callable and Runnable are used in the same way, the difference is:
1.Callable using the call () method, Runnable using the Run () method
2.call () can return a value, and the run () method cannot be returned.
3.call () can throw a checked exception, such as ClassNotFoundException, and run () cannot throw a checked exception.
Java.util.concurrent.Callable