当前位置: 首页>>代码示例>>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;未经允许,请勿转载。