summary

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 :

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

Technology
©2019-2020 Toolsou All rights reserved,
1190 Reverses the substring between each pair of parentheses leetcodemysql Joint index details You don't know ——HarmonyOS Create data mysql Library process Character recognition technology of vehicle license plate based on Neural Network A guess number of small games , use JavaScript realization Talking about uni-app Page value transfer problem pytorch of ResNet18( Yes cifar10 The accuracy of data classification is achieved 94%)C++ Method of detecting memory leak One is called “ Asking for the train ” A small village Finally got the train