當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。