当前位置:网站首页>Completable future practical usage
Completable future practical usage
2022-07-26 13:43:00 【CS beat you】
import com.atguigu.common.utils.R; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.ThreadPoolExecutor; @RestController @RequestMapping("/product/thread") public class ThreadTestController { @Autowired private ThreadPoolExecutor threadPoolExecutor; @RequestMapping("/test") public R test() throws Exception { long start = System.currentTimeMillis(); // First step , Asynchronous execution : no return value CompletableFuture<String> main = CompletableFuture.supplyAsync(() -> { try { Thread.sleep(3000L); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(" Performed the first task ...."); return "main"; }, threadPoolExecutor); // The second step , Wait for the completion of the first step to execute asynchronously CompletableFuture<Void> two = main.thenAcceptAsync((res) -> { try { Thread.sleep(3000L); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(" The second task was performed ....\t" + res); }, threadPoolExecutor); // The third step , Wait for the completion of the first step to execute asynchronously CompletableFuture<Void> thread = main.thenAcceptAsync((res) -> { try { Thread.sleep(3000L); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(" Performed the third task ....\t" + res); }, threadPoolExecutor); // Wait for all to complete CompletableFuture.allOf(main,two,thread).get(); System.out.println(" Main thread execution completed ....."); long end = System.currentTimeMillis(); System.out.println("main Always use time :"+(end-start)); // So it took a total of six seconds return R.ok(); } }
边栏推荐
- Intercept the coordinate points (four point coordinates of the face frame) face image from the marked XML file and save it in the specified folder
- 天津市应急局与驻津央企签署协议深化应急联动机制建设
- LCL three-phase PWM rectifier (inverter)
- Control the probability of random winning [C | random]
- [shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]
- 421. 数组中两个数的最大异或值
- Ros2 learning (1) introduction to ros2
- Tupu 3D visual national style design | collision between technology and culture "cool" spark“
- JSON数据传递参数&日期型参数传递
- 银行业客户体验管理现状与优化策略分析
猜你喜欢

重押海外:阿里、京东、顺丰再拼“内力”

Concept and handling of exceptions

力扣------字符串中的单词数
![[flower carving hands-on] fun music visualization series small project (12) -- meter tube fast rhythm light](/img/99/6581b8a576e59a13aa4e977e3a1b70.jpg)
[flower carving hands-on] fun music visualization series small project (12) -- meter tube fast rhythm light

Brief introduction of reflection mechanism

天津市应急局与驻津央企签署协议深化应急联动机制建设

Frisbee, 2022 "black red" top stream
![[flower carving hands-on] interesting and fun music visualization series small project (13) -- organic rod column lamp](/img/d4/7b9c7c99d46661e1be2963a342dd18.jpg)
[flower carving hands-on] interesting and fun music visualization series small project (13) -- organic rod column lamp

Implementation of SAP ABAP daemon

历时15年、拥有5亿用户的飞信,彻底死了
随机推荐
[flower carving hands-on] fun music visualization series small project (12) -- meter tube fast rhythm light
Mobile dual finger scaling event (native), e.originalevent.touches
Golang端口扫描设计
[dark horse morning post] many apps under bytek have been taken off the shelves; The leakage of deoxidizer in three squirrels caused pregnant women to eat by mistake; CBA claimed 406million yuan from
Control the probability of random winning [C | random]
Algorithm -- continuous sequence (kotlin)
Precautions for triggering pytest.main() from other files
[flower carving hands-on] interesting and fun music visualization series small project (13) -- organic rod column lamp
Sword finger offer (x): rectangular coverage
Frisbee, 2022 "black red" top stream
Analysis on the current situation and optimization strategy of customer experience management in banking industry
8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
Using the geoprocessor tool
天津市应急局与驻津央企签署协议深化应急联动机制建设
【Oauth2】七、微信OAuth2授权登录
Huawei computer test ~ offset realizes string encryption
Pytoch learning notes (I) installation and use of common functions
How to build a customer-centric product blueprint: suggestions from the chief technology officer
Official announcement! Edweisen group and Baidu xirang reached a deep co creation cooperation
JSON数据传递参数&日期型参数传递