Excutor Framework
The Excutor framework leaves the commit and execution of the task, and the task submission is spread across the program, but the execution policy can be set in one place, such as executing in a thread pool or serial, thread pool fixed length or longer, and all display using the new Thread (Task) Place should be considered under the Excutor framework
the task of carrying results callable and future
There are three ways to build a thread to perform a task, 1. Inherit thread. 2. Implement Runnable interface. 3. Implement callable interface. The callable abstraction can have a return value that represents the result of the task, submitting the callable task in Excutor, returning the future object, the future object wrapping the lifecycle of the entire task, and getting the return value.
Task Execution Exception
Future get gets callable execution result, throws in ' Te ' Rru ' P ' tedexception,excutionexception,can ' CE ' lationexception,timeoutexception
When an exception is thrown in a task, the call to Future's get gets the result, throws Excuteexception, and can invoke E.getcause to get the real exception.
Completionservice
If you have more than one parallel task, call the corresponding future's get when you obtain the result, if you need to finish first, then this method is not possible. You can use Completionservice, where an excutor is associated to submit a task, and a Completionservice take method is invoked to return the future structure of the completed task
set a time limit for a task
The future Get method can set timeout and call the Cancel method (the Cancel method is generally invoked after timeout)