CompletableFuture详解~thenApplyAsync
生活随笔
收集整理的這篇文章主要介紹了
CompletableFuture详解~thenApplyAsync
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
通過(guò)調(diào)用異步方法(方法后邊加Async后綴),串聯(lián)起來(lái)的CompletableFuture可以異步地執(zhí)行(使用ForkJoinPool.commonPool())。
static void thenApplyAsyncExample() {CompletableFuture cf = CompletableFuture.completedFuture("message").thenApplyAsync(s -> {assertTrue(Thread.currentThread().isDaemon());randomSleep();return s.toUpperCase();});assertNull(cf.getNow(null));assertEquals("MESSAGE", cf.join()); }總結(jié)
以上是生活随笔為你收集整理的CompletableFuture详解~thenApplyAsync的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: CompletableFuture详解~
- 下一篇: Scrapy源码阅读分析_1_整体框架和