本文整理汇总了Java中java.util.concurrent.CompletableFuture.thenRun方法的典型用法代码示例。如果您正苦于以下问题:Java CompletableFuture.thenRun方法的具体用法?Java CompletableFuture.thenRun怎么用?Java CompletableFuture.thenRun使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.CompletableFuture
的用法示例。
在下文中一共展示了CompletableFuture.thenRun方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testContinuationOrder
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Test
public void testContinuationOrder() {
AtomicInteger value = new AtomicInteger();
CompletableFuture<Void> future = new CompletableFuture<>();
future.thenRun(() -> value.set(1));
future.thenRun(() -> value.set(2));
future.complete(null);
Assert.assertEquals("Continuations are a stack, not a queue.", 1, value.get());
}
示例2: itExecutesReturnedFuturesOnTheProvidedExecutor
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Test
public void itExecutesReturnedFuturesOnTheProvidedExecutor() {
ExecutorService executorService = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("SmtpSessionTestExecutor").build());
SmtpSession session = new SmtpSession(channel, responseHandler, CONFIG, executorService, SSL_ENGINE_SUPPLIER);
CompletableFuture<SmtpClientResponse> future = session.send(SMTP_REQUEST);
CompletableFuture<Void> assertionFuture = future.thenRun(() -> assertThat(Thread.currentThread().getName()).contains("SmtpSessionTestExecutor"));
responseFuture.complete(Lists.newArrayList(OK_RESPONSE));
assertionFuture.join();
}
示例3: scheduleCleanUp
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@VisibleForTesting
void scheduleCleanUp(CompletableFuture<Void> future, FactsObserver factsObserver) {
ScheduledFuture<?> scheduleWithFixedDelay = executorService.scheduleWithFixedDelay(
new ConnectionCleanupRunnable(factsObserver, future), waitSecondsForCleanUpCheck,
waitSecondsForCleanUpCheck, TimeUnit.SECONDS);
future.thenRun(() -> scheduleWithFixedDelay.cancel(true));
}
示例4: ensureConstN
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Benchmark
public Void ensureConstN() throws InterruptedException, ExecutionException {
CompletableFuture<Void> f = constVoidFuture;
for (int i = 0; i < N.n; i++)
f = f.thenRun(ensureF);
return f.get();
}
示例5: ensurePromise
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Benchmark
public Void ensurePromise() throws InterruptedException, ExecutionException {
CompletableFuture<Void> p = new CompletableFuture<Void>();
CompletableFuture<Void> f = p.thenRun(ensureF);
p.complete(null);
return f.get();
}
示例6: ensurePromiseN
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Benchmark
public Void ensurePromiseN() throws InterruptedException, ExecutionException {
CompletableFuture<Void> p = new CompletableFuture<>();
CompletableFuture<Void> f = p;
for (int i = 0; i < N.n; i++)
f = f.thenRun(ensureF);
p.complete(null);
return f.get();
}
示例7:
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
public <T> CompletableFuture<Void> thenRun
(CompletableFuture<T> f, Runnable a) {
return f.thenRun(a);
}
示例8: itCanCreateAFutureInTheCallbackForAPreviousFuture
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Test
public void itCanCreateAFutureInTheCallbackForAPreviousFuture() throws Exception {
CompletableFuture<List<SmtpResponse>> future = responseHandler.createResponseFuture(1, DEBUG_STRING);
CompletableFuture<Void> assertion = future.thenRun(() -> assertThat(responseHandler.createResponseFuture(1, DEBUG_STRING)).isNotNull());
responseHandler.channelRead(context, SMTP_RESPONSE);
assertion.get();
}