ForkJoinPool forkJoinPool = new ForkJoinPool(2); forkJoinPool.submit(() -> //parallel task here, for example IntStream.range(1, 1_000_000).parallel().filter(PrimesPrint::isPrime).collect(toList()) ).get();
@Override public ExecutorService build( Group group, SchedulerThreadFactory factory, int threadCount ) { return new ForkJoinPool( threadCount, factory, null, false ); } };
/** * @see #shutdown() * @param threadPoolSize the number of concurrent threads * @since 2.9 * UserConfig added * @since 4.2 */ public MultiThreadedJLanguageTool(Language language, Language motherTongue, int threadPoolSize, UserConfig userConfig) { super(language, motherTongue, null, userConfig); this.threadPoolSize = threadPoolSize; threadPool = new ForkJoinPool(threadPoolSize, ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, false); }
public static synchronized ForkJoinPool getForkJoinPool() { if (forkJoinPool != null) return forkJoinPool; forkJoinPool = new ForkJoinPool(nThreads, ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); return forkJoinPool; }
ForkJoinPool forkJoinPool = new ForkJoinPool(2); CompletableFuture<List<Integer>> primes = CompletableFuture.supplyAsync(() -> //parallel task here, for example range(1, 1_000_000).parallel().filter(PrimesPrint::isPrime).collect(toList()), forkJoinPool );
@Override public void afterPropertiesSet() { this.forkJoinPool = (this.commonPool ? ForkJoinPool.commonPool() : new ForkJoinPool(this.parallelism, this.threadFactory, this.uncaughtExceptionHandler, this.asyncMode)); }
@Override public ExecutorService build( Group group, SchedulerThreadFactory factory ) { return new ForkJoinPool( getRuntime().availableProcessors(), factory, null, false ); }
public ForkJoinPool(boolean shared, final String threadName) { this.shared = shared; forkJoinPool = new java.util.concurrent.ForkJoinPool(Runtime.getRuntime().availableProcessors(), new java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory() { @Override public java.util.concurrent.ForkJoinWorkerThread newThread(java.util.concurrent.ForkJoinPool pool) { return new JDK7ForkJoinWorkerThread(pool, ForkJoinPool.this.shared, threadName); } }, null, false); logger.info("Using ForkJoinPool {}. Set the {} to -1 to fully use its power.", forkJoinPool.getClass().getName(), ApplicationConfig.BROADCASTER_ASYNC_WRITE_THREADPOOL_MAXSIZE); }
private ExecutorService createNewWorkStealingExecutor( Group group, int parallelism, boolean asyncMode ) { ForkJoinPool.ForkJoinWorkerThreadFactory factory = new GroupedDaemonThreadFactory( group, topLevelGroup ); return new ForkJoinPool( parallelism, factory, null, asyncMode ); }
/** * Creates a work-stealing thread pool using all * {@link Runtime#availableProcessors available processors} * as its target parallelism level. * @return the newly created thread pool * @since 1.8 * @hide */ public static ExecutorService newWorkStealingPool() { return new ForkJoinPool (Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); }
@Override public void afterPropertiesSet() { this.forkJoinPool = (this.commonPool ? ForkJoinPool.commonPool() : new ForkJoinPool(this.parallelism, this.threadFactory, this.uncaughtExceptionHandler, this.asyncMode)); }
public ForkJoinScheduler(int numThreads) { numThreads = numThreads >= 0 ? numThreads : Scheduler.defaultNumberThreads; pool = new ForkJoinPool(numThreads); timerService = new TimerService(this); }
@NoWarning("NP_NONNULL_PARAM_VIOLATION") public void testNominal() { new ForkJoinPool(2, ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); }
DirScanPool(Configuration conf) { String poolSize = conf.get(CHORE_POOL_SIZE, DEFAULT_CHORE_POOL_SIZE); size = calculatePoolSize(poolSize); // poolSize may be 0 or 0.0 from a careless configuration, // double check to make sure. size = size == 0 ? calculatePoolSize(DEFAULT_CHORE_POOL_SIZE) : size; pool = new ForkJoinPool(size); LOG.info("Cleaner pool size is {}", size); reconfigNotification = new AtomicBoolean(false); cleanerLatch = 0; }
/** * 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); }
public static ExecutorService newScalingThreadPool(final int maxThreads) { final ForkJoinPool.ForkJoinWorkerThreadFactory factory = pool -> { final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); worker.setName("OrbitThread-" + worker.getPoolIndex()); return worker; }; return new ForkJoinPool(maxThreads, factory, (t, e) -> logger.log(Level.SEVERE, "Uncaught exception", e), false); } }
@ExpectWarning("NP_NONNULL_PARAM_VIOLATION") public void testWarning() { new ForkJoinPool(2, null, new Handler(), true); } }
public static ExecutorService newWorkStealingPool(String threadName, int maxParallelThreads) { final ForkJoinWorkerThreadFactory factory = pool -> { ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); LoggingUncaughtExceptionHandler.setOnThread(worker); worker.setName(threadName + worker.getPoolIndex()); return worker; }; return new ForkJoinPool(maxParallelThreads, factory, null, true); }
@Override public void start() { forkJoinThreadPool = new ForkJoinPool(); config.enabledBoltConnectors().forEach( connector -> { BoltScheduler boltScheduler = new ExecutorBoltScheduler( connector.key(), executorFactory, scheduler, logService, config.get( connector.thread_pool_min_size ), config.get( connector.thread_pool_max_size ), config.get( connector.thread_pool_keep_alive ), config.get( connector.unsupported_thread_pool_queue_size ), forkJoinThreadPool ); boltScheduler.start(); boltSchedulers.put( connector.key(), boltScheduler ); } ); }
/** * Initializes a new instance using settings from the specified environment * instance. * @param env a defined instance */ public IndexerParallelizer(RuntimeEnvironment env) { int indexingParallelism = env.getIndexingParallelism(); // The order of the following is important. this.fixedExecutor = Executors.newFixedThreadPool(indexingParallelism); this.forkJoinPool = new ForkJoinPool(indexingParallelism); this.ctagsPool = new BoundedBlockingObjectPool<>(indexingParallelism, new CtagsValidator(), new CtagsObjectFactory(env)); }