stay jdk1.5 before , There are two ways to create a thread : One is direct inheritance Thread, The other is implementation Runnable Interface .

But this 2 There is a problem with both methods : Unable to get execution results after task execution . If you need to get the execution results , It must be achieved by sharing variables or message passing , It is more troublesome to use .

from Java
1.5 start , It provided Callable Class and Future class , Through them, we can get the result of task execution after the task is executed . After analysis and summary , We divide asynchronous computing threads into 3 part :

computational model

1, controller (Controller): Control thread of asynchronous computing , Responsible for the decomposition and initiation of asynchronous computing tasks , Leave the decomposed tasks to the asynchronous ones worker Thread to execute , After asynchronous computing is initiated ,controller Available Futrue Set of , Pass collection data to collector,collector according to Future To handle the results of asynchronous computation ;

2, processor (Wroker): Asynchronous computing thread , Responsible for specific calculation tasks ;

3, Result collector (Collector): Asynchronous calculation result collection thread , Get it from the initiating thread Future Set of , And responsible for monitoring Future Status of , according to Future To handle the results of asynchronous computation .

According to the above model , The asynchronous computation code is built as follows :

package com.ips.concurrent.future; import java.util.ArrayList; import
java.util.List;import java.util.concurrent.ExecutorServic

©2019-2020 Toolsou All rights reserved,
Final review of database : Summary of comprehensive application questions Laplance operator ( Second derivative ) Simple learning of computer composition principle pyqt Button call python program _PyQt: Link button to function in program How much can you go up once you change jobs ? Today, I saw the ceiling of job hopping python in str Function usage _python in str Usage Summary of built-in functions MySQL trigger web The server nginx---linux Installation and deployment C++ Chapter V polymorphism exercises :( It's coming to an end )python Check built-in functions , How to check python Built in function