Java.util.concurrent.Callable

Source: Internet
Author: User

/** * 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.