@ManagedAttribute(description="Current number of threads in the thread pool") public int getThreadPoolSize() { if(thread_pool instanceof ThreadPoolExecutor) return ((ThreadPoolExecutor)thread_pool).getPoolSize(); if(thread_pool instanceof ForkJoinPool) return ((ForkJoinPool)thread_pool).getPoolSize(); return 0; }
/** * Return the size of fork pool used for adding replica in map. */ @VisibleForTesting public static int getAddReplicaForkPoolSize() { return addReplicaThreadPool.getPoolSize(); } }
@Override public Integer getValue() { return fjPool().getPoolSize(); // Returns the number of worker threads that have started but not yet terminated. } });
@Override public int getPoolSize() { return java.util.concurrent.ForkJoinPool.commonPool().getPoolSize(); }
@Override public ForkJoinWorkerThread newThread(ForkJoinPool pool) { // note: pool.getPoolSize() includes the new (yet to be created) thread if (pool.getPoolSize() <= min(parallelism * scale, maxThreads)) { return defaultForkJoinWorkerThreadFactory.newThread(pool) ; } else { return null; } } }
@Override public int getPoolSize() { return fjPool().getPoolSize(); // Returns the number of worker threads that have started but not yet terminated. }
@ManagedAttribute(description="Current number of threads in the thread pool") public int getThreadPoolSize() { if(thread_pool instanceof ThreadPoolExecutor) return ((ThreadPoolExecutor)thread_pool).getPoolSize(); if(thread_pool instanceof ForkJoinPool) return ((ForkJoinPool)thread_pool).getPoolSize(); return 0; }
System.out.printf("ForkJoinpool contains %d Threads\n",fjPool.getPoolSize()); System.out.println("Running time: "+runningTime + " millisecs (" +(runningTime/1000.0) + ") secs"); System.out.println("============================================");
/** * Gets a snapshot of the given ExecutorService. * * @param service The ExecutorService to request a snapshot on. * @return A Snapshot of the given ExecutorService, or null if not supported. */ public static Snapshot getSnapshot(ExecutorService service) { Preconditions.checkNotNull(service, "service"); if (service instanceof ThreadPoolExecutor) { val tpe = (ThreadPoolExecutor) service; return new Snapshot(tpe.getQueue().size(), tpe.getActiveCount(), tpe.getPoolSize()); } else if (service instanceof ForkJoinPool) { val fjp = (ForkJoinPool) service; return new Snapshot(fjp.getQueuedSubmissionCount(), fjp.getActiveThreadCount(), fjp.getPoolSize()); } else { return null; } }
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); }
prefix, "thread_pool_size"), executorService.getPoolSize());
" activeThreads=" + pool.getActiveThreadCount() + " runningThreads=" + pool.getRunningThreadCount() + " poolSize=" + pool.getPoolSize() + " queuedTasks=" + pool.getQueuedTaskCount() + " queuedSubmissions=" + pool.getQueuedSubmissionCount() +