當前位置: 首頁>>代碼示例>>Java>>正文


Java CompletableFuture.whenCompleteAsync方法代碼示例

本文整理匯總了Java中java.util.concurrent.CompletableFuture.whenCompleteAsync方法的典型用法代碼示例。如果您正苦於以下問題:Java CompletableFuture.whenCompleteAsync方法的具體用法?Java CompletableFuture.whenCompleteAsync怎麽用?Java CompletableFuture.whenCompleteAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.CompletableFuture的用法示例。


在下文中一共展示了CompletableFuture.whenCompleteAsync方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: write

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Override
public void write(T event) throws Exception {

    checkWriteError();

    this.pendingWritesCount.incrementAndGet();
    final CompletableFuture<Void> future = pravegaWriter.writeEvent(eventRouter.getRoutingKey(event), event);
    future.whenCompleteAsync(
            (result, e) -> {
                if (e != null) {
                    log.warn("Detected a write failure: {}", e);

                    // We will record only the first error detected, since this will mostly likely help with
                    // finding the root cause. Storing all errors will not be feasible.
                    writeError.compareAndSet(null, e);
                }
                synchronized (this) {
                    pendingWritesCount.decrementAndGet();
                    this.notify();
                }
            },
            executorService
    );
}
 
開發者ID:pravega,項目名稱:flink-connectors,代碼行數:25,代碼來源:FlinkPravegaWriter.java

示例2: newRequestFuture

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
private CompletableFuture<Object> newRequestFuture(Object request, CoordinationRequestCallback callback) {
    CompletableFuture<Object> future = new CompletableFuture<>();

    future.whenCompleteAsync((response, error) -> {
        try {
            if (error == null) {
                if (DEBUG) {
                    log.debug("Received coordination response [from={}, message={}]", node, response);
                }

                callback.onResponse(response, this);
            } else {
                if (DEBUG) {
                    log.debug("Canceled coordination request sending [to={}, message={}]", node, request);
                }

                callback.onCancel();
            }
        } catch (RuntimeException | Error e) {
            log.error("Got an unexpected runtime error while notifying coordination request callback.", e);
        }
    }, async);

    return future;
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:26,代碼來源:DefaultCoordinationMember.java

示例3:

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
public <T> CompletableFuture<T> whenComplete
    (CompletableFuture<T> f,
     BiConsumer<? super T,? super Throwable> a) {
    return f.whenCompleteAsync(a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:CompletableFutureTest.java

示例4: ThreadExecutor

import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
public <T> CompletableFuture<T> whenComplete
    (CompletableFuture<T> f,
     BiConsumer<? super T,? super Throwable> a) {
    return f.whenCompleteAsync(a, new ThreadExecutor());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:CompletableFutureTest.java


注:本文中的java.util.concurrent.CompletableFuture.whenCompleteAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。