当前位置:网站首页>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();
边栏推荐
- 微信小程序自定义组件-城市选择「建议收藏」
- 罗克韦尔AB PLC RSLogix5000中定时器指令使用方法介绍
- 2022 Cloud Native Computing代表厂商 | 灵雀云第三次入选Gartner中国ICT技术成熟度曲线报告
- Qt:小的任务管理器(task)
- pyvista 的介绍与使用
- bash shell数组详解
- 浅聊偏函数
- LVS-DR集群部署
- leetcode动态规划系列(求路径篇)
- Cloud function to achieve automatic website check-in configuration details [Web function/Nodejs/cookie]
猜你喜欢
I am 37 this year, and I was rushed by a big factory to...
被Win11安全中心误删除的文件怎么恢复?
2022 Cloud Native Computing代表厂商 | 灵雀云第三次入选Gartner中国ICT技术成熟度曲线报告
Detailed explanation of MSTP protocol configuration on Layer 3 switches [Huawei eNSP experiment]
Detailed explanation of NAT/NAPT address translation (internal and external network communication) technology [Huawei eNSP]
cannot import name 'import_string' from 'werkzeug' [bug solution]
MindSpore:model.train中的dataset_sink_mode该如何理解?
Interview at 14:00 in the afternoon, I came out at 14:08 with my head down, asking too much...
冰蝎逆向初探
2022-08-03 第六小组 瞒春 学习笔记
随机推荐
使用ClickHouse分析COS的清单和访问日志
Cloud function to achieve automatic website check-in configuration details [Web function/Nodejs/cookie]
请问下Flink SQL如何写hologres分区表?我想要每天一个分区
罗克韦尔AB PLC RSLogix5000中定时器指令使用方法介绍
高级转录组分析和R数据可视化火热报名中(2022.10)
《福格行为模型》:如何养成好习惯?
双向带头循环链表实现
【C补充】指向指针或函数的指针
pyvista 的介绍与使用
云计算适合什么企业_当前全球云计算处于发展
HTB-Nibbles
v-model原理,在“radio”、“checkbox”、“select”、修饰符
MySQL binlog都有哪些模式?
无线Mesh自组网方案,CV5200无线模组应用,支持高清数据远距离传输
Win11怎么进行左右键对调?
ps抠图怎么抠出来,自学ps软件photoshop2022,ps怎么抠出想要的部分-笔记记录
Producer and Consumer Problems in Concurrent Programming
各位大佬,请问mysql数据的cdc,能指定存量数据同步的zone为utc 吗
用匿名函数定义函数_c语言最先执行的函数是
Win11系统重装用什么好 一键重装Win11教程