java.util.concurrent.ForkJoinPool.invokeAll()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(4.0k)|赞(0)|评价(0)|浏览(146)

本文整理了Java中java.util.concurrent.ForkJoinPool.invokeAll()方法的一些代码示例,展示了ForkJoinPool.invokeAll()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ForkJoinPool.invokeAll()方法的具体详情如下:
包路径:java.util.concurrent.ForkJoinPool
类名称:ForkJoinPool
方法名:invokeAll

ForkJoinPool.invokeAll介绍

暂无

代码示例

代码示例来源:origin: tantaman/commons

public static <T> void ForFJ(final Iterable<T> elements, final Operation<T> operation) {
 // TODO: is this really utilizing any fork-join capabilities since it is just an invokeAll?
 // I assume work stealing is at least going on since this is sumbitted to a fork-join pool?
 // but performance tests don't show a different between this and the old way.
   fjPool.invokeAll(createCallables(elements, operation));
}

代码示例来源:origin: lejon/T-SNE-Java

public List<Future<ParallelTreeNode.TreeSearchResult>> searchMultiple(ParallelVpTree<StorageType> tree, DataPoint [] targets, int k) {
  List<ParallelTreeNode.ParallelTreeSearcher> searchers = new ArrayList<>();
  for(int n = 0; n < targets.length; n++) {
    @SuppressWarnings("unchecked")
    ParallelTreeNode node = (ParallelTreeNode) tree.getRoot();
    searchers.add(node.new ParallelTreeSearcher(node,_items,targets[n], k, n));
  }
  List<Future<ParallelTreeNode.TreeSearchResult>> results =  searcherPool.invokeAll(searchers);
  return results;
}

代码示例来源:origin: net.sf.phat/phat-audio

private void concurrentNotification(final MicrophoneData md) {
  ForkJoinPool pool = new ForkJoinPool();
  for (NotifyTask n : callables) {
    n.setMicrophoneData(md);
  }
  pool.invokeAll(callables);
}

代码示例来源:origin: com.github.haifengl/smile-math

/**
 * Pairwise distance between pairs of objects.
 * @param x Rows of x correspond to observations, and columns correspond to variables.
 * @param squared If true, compute the squared Euclidean distance.
 * @param half If true, only the lower half of dist will be referenced.
 * @param dist The distance matrix.
 */
public static void pdist(double[][] x, double[][] dist, boolean squared, boolean half) {
  int n = x.length;
  if (n < 100) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < i; j++) {
        double d = distance(x[i], x[j]);
        dist[i][j] = d;
        dist[j][i] = d;
      }
    }
  } else {
    int nprocs = Runtime.getRuntime().availableProcessors();
    List<PdistTask> tasks = new ArrayList<>();
    for (int i = 0; i < nprocs; i++) {
      PdistTask task = new PdistTask(x, dist, nprocs, i, squared, half);
      tasks.add(task);
    }
    ForkJoinPool.commonPool().invokeAll(tasks);
  }
}

代码示例来源:origin: usc-cloud/goffish

List<Future<Object>> results = _pool.invokeAll(computeList);

代码示例来源:origin: io.syndesis.common/common-util

@Test
public void testCreateKeyMultithreaded() {
  final int count = 100000;
  final Collection<Callable<String>> tasks = IntStream.range(0, count).boxed()
    .map(i -> (Callable<String>) () -> KeyGenerator.createKey()).collect(Collectors.toList());
  final ForkJoinPool pool = ForkJoinPool.commonPool();
  final List<Future<String>> results = pool.invokeAll(tasks);
  final Set<String> keys = results.stream().map(t -> {
    try {
      return t.get();
    } catch (InterruptedException | ExecutionException e) {
      throw new IllegalStateException(e);
    }
  }).collect(Collectors.toSet());
  Assert.assertEquals("If " + count + " key generations are performed in parallel, it should yield " + count
    + " of distinct keys", count, keys.size());
}

代码示例来源:origin: io.syndesis/core

@Test
public void testCreateKeyMultithreaded() {
  final int count = 100000;
  final Collection<Callable<String>> tasks = IntStream.range(0, count).boxed()
    .map(i -> (Callable<String>) () -> KeyGenerator.createKey()).collect(Collectors.toList());
  final ForkJoinPool pool = ForkJoinPool.commonPool();
  final List<Future<String>> results = pool.invokeAll(tasks);
  final Set<String> keys = results.stream().map(t -> {
    try {
      return t.get();
    } catch (InterruptedException | ExecutionException e) {
      throw new IllegalStateException(e);
    }
  }).collect(Collectors.toSet());
  Assert.assertEquals("If " + count + " key generations are performed in parallel, it should yield " + count
    + " of distinct keys", count, keys.size());
}

代码示例来源:origin: theonedev/onedev

for (Future<Void> future: OneDev.getInstance(ForkJoinPool.class).invokeAll(tasks)) {
  try {

相关文章

ForkJoinPool类方法