Interface Callable <V> Type Parameter Structure type of the V-Call method

public interface Callable<V>  

A task that returns results and may throw exceptions. The implementer defines a call() method that takes no arguments,

The Callable interface is similar to Runnable in that both are designed for classes where real instances might be executed by another thread,

But Runnable does not return results and cannot throw checked exceptions

The Executors class contains some useful methods for converting from other common forms to the Callable class.

 

 

public interface Future<V> 
Copy the code
Copy the code

Future represents the result of asynchronous computation. It provides a way to check that a calculation is complete, wait for it to complete, and get the results of the calculation.

After the calculation is complete, you can only use the get method to get the results, and if necessary, you can block this method until the calculation is complete. Cancellation is done by the cancel method

To execute. Additional methods are provided to determine whether a task completed normally or was cancelled. Once the calculation is complete, it cannot be cancelled.

If a Future is used for cancelability but no results are available, you can declare a Future
, and returns NULL as the result of the underlying task.

 

 

 

 

The difference between Callable and Runnable is as follows:

I Callable defines the call method and Runnable defines the run method.

II The call method of a Callable can have a return value, while the run method of a Runnable cannot.

III The call method of a Callable can throw an exception, while the run method of a Runnable cannot.

 
Copy the code