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

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

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

ForkJoinPool.getParallelism介绍

[英]Returns the targeted parallelism level of this pool.
[中]返回此池的目标并行级别。

代码示例

代码示例来源:origin: kilim/kilim

public int numThreads() {
  return pool.getParallelism();
}

代码示例来源:origin: reactor/reactor-core

/**
 * This method will attempt to compute the maximum amount of subscribers a
 * {@link WorkQueueProcessor} can accommodate based on a given {@link ExecutorService}.
 * <p>
 * It can only accurately detect this for {@link ThreadPoolExecutor} and
 * {@link ForkJoinPool} instances, and will return {@link Integer#MIN_VALUE} for other
 * executor implementations.
 *
 * @param executor the executor to attempt to introspect.
 * @return the maximum number of subscribers the executor can accommodate if it can
 * be computed, or {@link Integer#MIN_VALUE} if it cannot be determined.
 */
static int bestEffortMaxSubscribers(ExecutorService executor) {
  int maxSubscribers = Integer.MIN_VALUE;
  if (executor instanceof ThreadPoolExecutor) {
    maxSubscribers = ((ThreadPoolExecutor) executor).getMaximumPoolSize();
  }
  else if (executor instanceof ForkJoinPool) {
    maxSubscribers = ((ForkJoinPool) executor).getParallelism();
  }
  return maxSubscribers;
}

代码示例来源:origin: apache/hbase

/**
 * Update pool with new size.
 */
synchronized void updatePool(long timeout) {
 long stopTime = System.currentTimeMillis() + timeout;
 while (cleanerLatch != 0 && timeout > 0) {
  try {
   wait(timeout);
   timeout = stopTime - System.currentTimeMillis();
  } catch (InterruptedException ie) {
   Thread.currentThread().interrupt();
   break;
  }
 }
 shutDownNow();
 LOG.info("Update chore's pool size from {} to {}", pool.getParallelism(), size);
 pool = new ForkJoinPool(size);
}

代码示例来源:origin: RoaringBitmap/RoaringBitmap

private static int availableParallelism() {
 return ForkJoinTask.inForkJoinPool()
     ? ForkJoinTask.getPool().getParallelism()
     : ForkJoinPool.getCommonPoolParallelism();
}

代码示例来源:origin: RoaringBitmap/RoaringBitmap

private static int availableParallelism() {
 return ForkJoinTask.inForkJoinPool()
     ? ForkJoinTask.getPool().getParallelism()
     : ForkJoinPool.getCommonPoolParallelism();
}

代码示例来源:origin: de.unijena.bioinf/jjobs-core

public int getThreads() {
  return executor.getParallelism();
}

代码示例来源:origin: org.jppf/jppf-common

@Override
public int getPoolSize() {
 return threadPool.getParallelism();
}

代码示例来源:origin: dhale/jtk

/**
 * Constructs a wrapper for objects that are not thread-safe.
 */
public Unsafe() {
 int initialCapacity = 16; // the default initial capacity
 float loadFactor = 0.5f; // huge numbers of threads are unlikely
 int concurrencyLevel = 2*_pool.getParallelism();
 _map = new ConcurrentHashMap<Thread,T>(
  initialCapacity,loadFactor,concurrencyLevel);
}

代码示例来源:origin: io.projectreactor/reactor-core

/**
 * This method will attempt to compute the maximum amount of subscribers a
 * {@link WorkQueueProcessor} can accommodate based on a given {@link ExecutorService}.
 * <p>
 * It can only accurately detect this for {@link ThreadPoolExecutor} and
 * {@link ForkJoinPool} instances, and will return {@link Integer#MIN_VALUE} for other
 * executor implementations.
 *
 * @param executor the executor to attempt to introspect.
 * @return the maximum number of subscribers the executor can accommodate if it can
 * be computed, or {@link Integer#MIN_VALUE} if it cannot be determined.
 */
static int bestEffortMaxSubscribers(ExecutorService executor) {
  int maxSubscribers = Integer.MIN_VALUE;
  if (executor instanceof ThreadPoolExecutor) {
    maxSubscribers = ((ThreadPoolExecutor) executor).getMaximumPoolSize();
  }
  else if (executor instanceof ForkJoinPool) {
    maxSubscribers = ((ForkJoinPool) executor).getParallelism();
  }
  return maxSubscribers;
}

代码示例来源:origin: co.paralleluniverse/quasar-core

@Override
  public Integer getValue() {
    return fjPool().getParallelism(); // Returns the targeted parallelism level of this pool.
  }
});

代码示例来源:origin: dunwu/javacore

private static void test1() {
    // -Djava.util.concurrent.ForkJoinPool.common.parallelism=5

    ForkJoinPool commonPool = ForkJoinPool.commonPool();
    System.out.println(commonPool.getParallelism());
  }
}

代码示例来源:origin: co.paralleluniverse/quasar-core

@Override
public int getParallelism() {
  return fjPool().getParallelism(); // Returns the targeted parallelism level of this pool.
}

代码示例来源:origin: horrorho/InflatableDonkey

public void execute(HttpClient httpClient, FileAssembler fileAssembler, List<Set<Asset>> batchedAssets) {
    logger.debug("-- execute() - threads: {} batch count: {}", forkJoinPool.getParallelism(), batchedAssets.size());
    try {
      forkJoinPool.submit(() -> batchedAssets
          .parallelStream()
          .forEach(u -> donkey.apply(httpClient, forkJoinPoolAux, u, fileAssembler)))
          .get();

    } catch (InterruptedException ex) {
      logger.warn("-- execute() - InterruptedException: {}", ex.getMessage());
      Thread.currentThread().interrupt();

    } catch (ExecutionException ex) {
      throw new RuntimeException(ex);
    }
  }
}

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

_vertexPartitions = new ConcurrentHashMap<>(numVertices, 1f, Math.min(_pool.getParallelism(), streams.size()));
_partitionSizes = new AtomicInteger[_numPartitions];
for (int i = 0; i < _partitionSizes.length; i++) {

代码示例来源:origin: org.junit.platform/junit-platform-engine

/**
 * Create a new {@code ForkJoinPoolHierarchicalTestExecutorService} based on
 * the supplied {@link ConfigurationParameters}.
 *
 * @see DefaultParallelExecutionConfigurationStrategy
 */
public ForkJoinPoolHierarchicalTestExecutorService(ConfigurationParameters configurationParameters) {
  forkJoinPool = createForkJoinPool(configurationParameters);
  parallelism = forkJoinPool.getParallelism();
  LoggerFactory.getLogger(getClass()).config(() -> "Using ForkJoinPool with parallelism of " + parallelism);
}

代码示例来源:origin: com.googlecode.junit-toolbox/junit-toolbox

static ForkJoinPool setUpForkJoinPool() {
  int numThreads;
  try {
    String configuredNumThreads = System.getProperty("maxParallelTestThreads");
    numThreads = Math.max(2, Integer.parseInt(configuredNumThreads));
  } catch (Exception ignored) {
    Runtime runtime = Runtime.getRuntime();
    numThreads = Math.max(2, runtime.availableProcessors());
  }
  ForkJoinPool.ForkJoinWorkerThreadFactory threadFactory = pool -> {
    if (pool.getPoolSize() >= pool.getParallelism()) {
      return null;
    } else {
      ForkJoinWorkerThread thread = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
      thread.setName("JUnit-" + thread.getName());
      return thread;
    }
  };
  return new ForkJoinPool(numThreads, threadFactory, null, false);
}

代码示例来源:origin: MichaelTamm/junit-toolbox

static ForkJoinPool setUpForkJoinPool() {
  int numThreads;
  try {
    String configuredNumThreads = System.getProperty("maxParallelTestThreads");
    numThreads = Math.max(2, Integer.parseInt(configuredNumThreads));
  } catch (Exception ignored) {
    Runtime runtime = Runtime.getRuntime();
    numThreads = Math.max(2, runtime.availableProcessors());
  }
  ForkJoinPool.ForkJoinWorkerThreadFactory threadFactory = pool -> {
    if (pool.getPoolSize() >= pool.getParallelism()) {
      return null;
    } else {
      ForkJoinWorkerThread thread = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
      thread.setName("JUnit-" + thread.getName());
      return thread;
    }
  };
  return new ForkJoinPool(numThreads, threadFactory, null, false);
}

代码示例来源:origin: com.oracle.substratevm/svm

protected static void initializeCommonPool_JDK8OrEarlier() {
  /* "common" and "commonParallelism" have to be set together. */
  /*
   * This is a simplified version of ForkJoinPool.makeCommonPool(), without the dynamic
   * class loading for factory and handler based on system properties.
   */
  int parallelism = Runtime.getRuntime().availableProcessors() - 1;
  if (!SubstrateOptions.MultiThreaded.getValue()) {
    /*
     * Using "parallelism = 0" gets me a ForkJoinPool that does not try to start any
     * threads, which is what I want if I am not multi-threaded.
     */
    parallelism = 0;
  }
  if (parallelism > MAX_CAP) {
    parallelism = MAX_CAP;
  }
  final Target_java_util_concurrent_ForkJoinPool proposedPool = new Target_java_util_concurrent_ForkJoinPool(parallelism, defaultForkJoinWorkerThreadFactory, null, LIFO_QUEUE,
          "ForkJoinPool.commonPool-worker-");
  /* The assignment to "injectedCommon" is atomic to prevent races. */
  injectedCommon.compareAndSet(null, proposedPool);
  final ForkJoinPool actualPool = Util_java_util_concurrent_ForkJoinPool.as_ForkJoinPool(injectedCommon.get());
  /*
   * The assignment to "commonParallelism" can race because multiple assignments are
   * idempotent once "injectedCommon" is set. This code is a copy of the relevant part of
   * the static initialization block in ForkJoinPool.
   */
  commonParallelism = actualPool.getParallelism();
}

代码示例来源:origin: org.roaringbitmap/RoaringBitmap

private static int availableParallelism() {
 return ForkJoinTask.inForkJoinPool()
     ? ForkJoinTask.getPool().getParallelism()
     : ForkJoinPool.getCommonPoolParallelism();
}

代码示例来源:origin: org.roaringbitmap/RoaringBitmap

private static int availableParallelism() {
 return ForkJoinTask.inForkJoinPool()
     ? ForkJoinTask.getPool().getParallelism()
     : ForkJoinPool.getCommonPoolParallelism();
}

相关文章

微信公众号

最新文章

更多

ForkJoinPool类方法