本文整理汇总了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
);
}
示例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;
}
示例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);
}
示例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());
}