public int numThreads() { return pool.getParallelism(); }
/** * 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; }
/** * 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); }
private static int availableParallelism() { return ForkJoinTask.inForkJoinPool() ? ForkJoinTask.getPool().getParallelism() : ForkJoinPool.getCommonPoolParallelism(); }
private static int availableParallelism() { return ForkJoinTask.inForkJoinPool() ? ForkJoinTask.getPool().getParallelism() : ForkJoinPool.getCommonPoolParallelism(); }
public int getThreads() { return executor.getParallelism(); }
@Override public int getPoolSize() { return threadPool.getParallelism(); }
/** * 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); }
/** * 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; }
@Override public Integer getValue() { return fjPool().getParallelism(); // Returns the targeted parallelism level of this pool. } });
private static void test1() { // -Djava.util.concurrent.ForkJoinPool.common.parallelism=5 ForkJoinPool commonPool = ForkJoinPool.commonPool(); System.out.println(commonPool.getParallelism()); } }
@Override public int getParallelism() { return fjPool().getParallelism(); // Returns the targeted parallelism level of this pool. }
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); } } }
_vertexPartitions = new ConcurrentHashMap<>(numVertices, 1f, Math.min(_pool.getParallelism(), streams.size())); _partitionSizes = new AtomicInteger[_numPartitions]; for (int i = 0; i < _partitionSizes.length; i++) {
/** * 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); }
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); }
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); }
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(); }
private static int availableParallelism() { return ForkJoinTask.inForkJoinPool() ? ForkJoinTask.getPool().getParallelism() : ForkJoinPool.getCommonPoolParallelism(); }
private static int availableParallelism() { return ForkJoinTask.inForkJoinPool() ? ForkJoinTask.getPool().getParallelism() : ForkJoinPool.getCommonPoolParallelism(); }