本文整理匯總了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());
}