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


Java CompletableFuture.anyOf方法代码示例

本文整理汇总了Java中java.util.concurrent.CompletableFuture.anyOf方法的典型用法代码示例。如果您正苦于以下问题:Java CompletableFuture.anyOf方法的具体用法?Java CompletableFuture.anyOf怎么用?Java CompletableFuture.anyOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.CompletableFuture的用法示例。


在下文中一共展示了CompletableFuture.anyOf方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAnyOf_normal

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * anyOf returns a future completed normally with a value when
 * a component future does
 */
public void testAnyOf_normal() throws Exception {
    for (int k = 0; k < 10; k++) {
        CompletableFuture[] fs = new CompletableFuture[k];
        for (int i = 0; i < k; i++)
            fs[i] = new CompletableFuture<>();
        CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
        checkIncomplete(f);
        for (int i = 0; i < k; i++) {
            fs[i].complete(i);
            checkCompletedNormally(f, 0);
            int x = (int) CompletableFuture.anyOf(fs).join();
            assertTrue(0 <= x && x <= i);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:CompletableFutureTest.java

示例2: testAnyOf_exceptional

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * anyOf result completes exceptionally when any component does.
 */
public void testAnyOf_exceptional() throws Exception {
    for (int k = 0; k < 10; k++) {
        CompletableFuture[] fs = new CompletableFuture[k];
        CFException[] exs = new CFException[k];
        for (int i = 0; i < k; i++) {
            fs[i] = new CompletableFuture<>();
            exs[i] = new CFException();
        }
        CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
        checkIncomplete(f);
        for (int i = 0; i < k; i++) {
            fs[i].completeExceptionally(exs[i]);
            checkCompletedWithWrappedException(f, exs[0]);
            checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs));
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:CompletableFutureTest.java

示例3: testAnyOf_exceptional_backwards

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
public void testAnyOf_exceptional_backwards() throws Exception {
    for (int k = 0; k < 10; k++) {
        CompletableFuture[] fs = new CompletableFuture[k];
        CFException[] exs = new CFException[k];
        for (int i = 0; i < k; i++) {
            fs[i] = new CompletableFuture<>();
            exs[i] = new CFException();
        }
        CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
        checkIncomplete(f);
        for (int i = k - 1; i >= 0; i--) {
            fs[i].completeExceptionally(exs[i]);
            checkCompletedWithWrappedException(f, exs[k - 1]);
            checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs));
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:CompletableFutureTest.java

示例4: doInvokeAny

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> CompletableFuture<T> doInvokeAny(Collection<? extends Callable<T>> tasks) {
  Objects.requireNonNull(tasks, "'tasks' should not be 'null'.");
  if (tasks.isEmpty()) {
    throw new IllegalArgumentException("'tasks' should not be empty.");
  }
  CompletableFuture[] futures = new CompletableFuture[tasks.size()];
  int index = 0;
  for (Callable<T> task : tasks) {
    futures[index++] = submit(task);
  }
  return (CompletableFuture<T>) CompletableFuture.anyOf(futures);
}
 
开发者ID:sorokinigor,项目名称:yet-another-try,代码行数:14,代码来源:AbstractRetryExecutorService.java

示例5: testAnyOf_empty

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * anyOf(no component futures) returns an incomplete future
 */
public void testAnyOf_empty() throws Exception {
    for (Integer v1 : new Integer[] { 1, null })
{
    CompletableFuture<Object> f = CompletableFuture.anyOf();
    checkIncomplete(f);

    f.complete(v1);
    checkCompletedNormally(f, v1);
}}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:CompletableFutureTest.java

示例6: testAnyOf_normal_backwards

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
public void testAnyOf_normal_backwards() throws Exception {
    for (int k = 0; k < 10; k++) {
        CompletableFuture[] fs = new CompletableFuture[k];
        for (int i = 0; i < k; i++)
            fs[i] = new CompletableFuture<>();
        CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
        checkIncomplete(f);
        for (int i = k - 1; i >= 0; i--) {
            fs[i].complete(i);
            checkCompletedNormally(f, k - 1);
            int x = (int) CompletableFuture.anyOf(fs).join();
            assertTrue(i <= x && x <= k - 1);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:CompletableFutureTest.java

示例7: anyOfMyProcesses

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
private CompletableFuture anyOfMyProcesses() {
    return CompletableFuture.anyOf(
            completableFuturesOfTheProcesses());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-9,代码行数:5,代码来源:ControlDaemon.java


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