Java custom task class timed task execution example callable and future interface usage

Callable and future interfaces callable is an interface similar to runnable. The classes implementing callable interface and runnable are tasks that can be executed by other threads. Callable is different from runnable in several ways: (1) callable specifies call (), while runnable specifies run () (2) Callable tasks can return values after execution, while runnable tasks cannot. (3) call () method can throw exceptions, while run () method cannot throw exceptions. (4) Run the callable task to get a future object. Future represents the result of asynchronous calculation. It provides a method to check whether the calculation is completed, wait for the calculation to be completed, and retrieve the calculation result. Through the future object, you can understand the task execution, cancel the task execution, and obtain the task execution result.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>