当前位置: 首页>>代码示例>>Java>>正文


Java CompletableFuture.thenRun方法代码示例

本文整理汇总了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());
}
 
开发者ID:tunnelvisionlabs,项目名称:java-threading,代码行数:10,代码来源:AsyncTest.java

示例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();
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:12,代码来源:SmtpSessionTest.java

示例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));
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:9,代码来源:FactsObserverFactory.java

示例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();
}
 
开发者ID:traneio,项目名称:future,代码行数:8,代码来源:JavaSyncFutureBenchmark.java

示例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();
}
 
开发者ID:traneio,项目名称:future,代码行数:8,代码来源:JavaSyncFutureBenchmark.java

示例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();
}
 
开发者ID:traneio,项目名称:future,代码行数:10,代码来源:JavaSyncFutureBenchmark.java

示例7:

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
public <T> CompletableFuture<Void> thenRun
    (CompletableFuture<T> f, Runnable a) {
    return f.thenRun(a);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:CompletableFutureTest.java

示例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();
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:11,代码来源:ResponseHandlerTest.java


注:本文中的java.util.concurrent.CompletableFuture.thenRun方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。