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

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

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

ForkJoinPool.getPoolSize介绍

[英]Returns the number of worker threads that have started but not yet terminated. The result returned by this method may differ from #getParallelism when threads are created to maintain parallelism when others are cooperatively blocked.
[中]返回已启动但尚未终止的工作线程数。此方法返回的结果可能不同于#getParallelism,即创建线程以在其他线程被协作阻止时保持并行性。

代码示例

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

@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;
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

/**
  * Return the size of fork pool used for adding replica in map.
  */
 @VisibleForTesting
 public static int getAddReplicaForkPoolSize() {
  return addReplicaThreadPool.getPoolSize();
 }
}

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

@Override
  public Integer getValue() {
    return fjPool().getPoolSize(); // Returns the number of worker threads that have started but not yet terminated.
  }
});

代码示例来源:origin: coffeewar/enode-master

@Override
public int getPoolSize() {
  return java.util.concurrent.ForkJoinPool.commonPool().getPoolSize();
}

代码示例来源:origin: com.obsidiandynamics.indigo/indigo-core

@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;
  }
 }
}

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

@Override
public int getPoolSize() {
  return fjPool().getPoolSize(); // Returns the number of worker threads that have started but not yet terminated.
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

@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;
}

代码示例来源:origin: stackoverflow.com

System.out.printf("ForkJoinpool contains %d Threads\n",fjPool.getPoolSize());
System.out.println("Running time: "+runningTime + " millisecs (" +(runningTime/1000.0) + ") secs");
System.out.println("============================================");

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

/**
 * 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;
  }
}

代码示例来源: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.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: com.arpnetworking.metrics.extras/jvm-extra

prefix,
    "thread_pool_size"),
executorService.getPoolSize());

代码示例来源:origin: stackoverflow.com

" activeThreads=" + pool.getActiveThreadCount() +
" runningThreads=" + pool.getRunningThreadCount() +
" poolSize=" + pool.getPoolSize() +
" queuedTasks=" + pool.getQueuedTaskCount() +
" queuedSubmissions=" + pool.getQueuedSubmissionCount() +

相关文章

ForkJoinPool类方法