当前位置:网站首页>Introduction to the core methods of the CompletableFuture interface
Introduction to the core methods of the CompletableFuture interface
2022-08-04 10:02:00 【Mitsui 08】
CompletableFuture can be seen as an upgraded version of the futuretask interface
To get the object, use these four methods:
runAsync(Runnable runnable,Executor executor) ;runAsync(Runnable runnable);supplyAsync(Supplier supplier);supplyAsync(Supplier supplier, Executor executor)Demo:
ExecutorService executorService = Executors.newFixedThreadPool(3);/*** Construct with no return value*/CompletableFuture voidCompletableFuture = CompletableFuture.runAsync(() -> {System.out.println(Thread.currentThread().getName()+"No return value");try {TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {throw new RuntimeException(e);}}, executorService);try {TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {throw new RuntimeException(e);}/*** create a return value*/CompletableFuture uCompletableFuture = CompletableFuture.supplyAsync(() -> {System.out.println(Thread.currentThread().getName() + "return value");try {TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {throw new RuntimeException(e);}return "hello supplier";}, executorService);System.out.println(voidCompletableFuture.get());System.out.println(uCompletableFuture.get());executorService.shutdown(); 边栏推荐
猜你喜欢

Win10电脑经常发出叮咚声音怎么关闭

罗克韦尔AB PLC RSLogix5000中定时器指令使用方法介绍
![Detailed explanation of MSTP protocol configuration on Layer 3 switches [Huawei eNSP experiment]](/img/97/6c3662ef36b02bc42eec95abaa6bc5.png)
Detailed explanation of MSTP protocol configuration on Layer 3 switches [Huawei eNSP experiment]

MindSpore:【model_zoo】【resnet】尝试用THOR优化器运行时报cannot import name ‘THOR‘

LeetCode中等题之设计循环队列

LVS+Keepalived群集部署

Apache APISIX 2.15 版本发布,为插件增加更多灵活性
![[Cloud Residency Co-Creation] HCSD Celebrity Live Streaming – Employment Guide](/img/50/86f0edaab8317e22c9ffdb2a2c6e93.png)
[Cloud Residency Co-Creation] HCSD Celebrity Live Streaming – Employment Guide

被Win11安全中心误删除的文件怎么恢复?

VRRP + MSTP configuration, huawei eNSP experiment 】 【
随机推荐
leetcode每天5题-Day06
使用ClickHouse分析COS的清单和访问日志
2022 Cloud Native Computing代表厂商 | 灵雀云第三次入选Gartner中国ICT技术成熟度曲线报告
冰蝎逆向初探
[Punctuality Atom STM32 Serial] Chapter 4 STM32 First Experience Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1
江西发布紧急通知:全面开展涉校涉生安全隐患大排查
各位大佬,请问mysql数据的cdc,能指定存量数据同步的zone为utc 吗
LVGL's multi-language conversion tool -- a good assistant for font settings
LVS负载均衡群集
[论文阅读] Unpaired Image-to-Image Translation Using Adversarial Consistency Loss
双重for循环案例以及while循环和do while循环案例
一文带你了解 ESLint
Detailed explanation of MSTP protocol configuration on Layer 3 switches [Huawei eNSP experiment]
rk3399-339 usb设备复合 总体流程
Detailed explanation of switch link aggregation [Huawei eNSP]
matlab练习程序(多线段交点)
请问下Flink SQL如何写hologres分区表?我想要每天一个分区
Multimedia and Internet of Things technology make the version "live" 129 vinyl records "Centennial Voice"
EastWave应用:自动计算光子晶体透反率
MindSpore:图算融合报错