CompletableFuture 创建异步对象
生活随笔
收集整理的這篇文章主要介紹了
CompletableFuture 创建异步对象
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
CompletableFuture 提供了四個(gè)靜態(tài)方法來(lái)創(chuàng)建一個(gè)異步操作。
static CompletableFuture<Void> runAsync(Runnable runnable) public static CompletableFuture<Void> runAsync(Runnable runnable, Executor executor) public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier) public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier, Executor executor)沒(méi)有指定Executor的方法會(huì)使用ForkJoinPool.commonPool() 作為它的線程池執(zhí)行異步代碼。如果指定線程池,則使用指定的線程池運(yùn)行。以下所有的方法都類同。
-
runAsync方法不支持返回值。
-
supplyAsync可以支持返回值。
總結(jié)
以上是生活随笔為你收集整理的CompletableFuture 创建异步对象的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: CompletableFuture介绍
- 下一篇: CompletableFuture计算完