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