CompletableFuture详解~thenApplyAsync
生活随笔
收集整理的這篇文章主要介紹了
CompletableFuture详解~thenApplyAsync
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
通過調用異步方法(方法后邊加Async后綴),串聯起來的CompletableFuture可以異步地執行(使用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()); }總結
以上是生活随笔為你收集整理的CompletableFuture详解~thenApplyAsync的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CompletableFuture详解~
- 下一篇: Scrapy源码阅读分析_1_整体框架和