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

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

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

ForkJoinPool.getActiveThreadCount介绍

[英]Returns an estimate of the number of threads that are currently stealing or executing tasks. This method may overestimate the number of active threads.
[中]返回当前正在窃取或执行任务的线程数的估计值。此方法可能会高估活动线程的数量。

代码示例

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

@Override
  public Integer getValue() {
    return fjPool().getActiveThreadCount();
  }
});

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

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

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

@Override
public int getActiveThreadCount() {
  return fjPool().getActiveThreadCount();
}

代码示例来源: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: coffeewar/enode-master

System.out.println("before f1 thread count:" + ForkJoinPool.commonPool().getActiveThreadCount());
  System.out.println("f1");
  Thread.sleep(10000);
  System.out.println("f1 end.");
  System.out.println("after f1 thread count:" + ForkJoinPool.commonPool().getActiveThreadCount());
} catch (InterruptedException e) {
  e.printStackTrace();
  System.out.println("before f2 thread count:" + ForkJoinPool.commonPool().getActiveThreadCount());
  System.out.println("f2");
  Thread.sleep(11000);
  System.out.println("f2 end.");
  System.out.println("after f2 thread count:" + ForkJoinPool.commonPool().getActiveThreadCount());
} catch (InterruptedException e) {
  e.printStackTrace();
  System.out.println("before f3 thread count:" + ForkJoinPool.commonPool().getActiveThreadCount());
  System.out.println("f3");
  Thread.sleep(12000);
  System.out.println("f3 end.");
  System.out.println("after f3 thread count:" + ForkJoinPool.commonPool().getActiveThreadCount());
} catch (InterruptedException e) {
  e.printStackTrace();
  System.out.println("before f4 thread count:" + ForkJoinPool.commonPool().getActiveThreadCount());
  System.out.println("f4");
  Thread.sleep(13000);
  System.out.println("f4 end.");
  System.out.println("after f4 thread count:" + ForkJoinPool.commonPool().getActiveThreadCount());

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

@Override
public ForkJoinInfo getInfo() {
  final ForkJoinPool fjPool = fjPool();
  int activeThreadCount = fjPool.getActiveThreadCount(); // Returns an estimate of the number of threads that are currently stealing or executing tasks.
  int runningThreadCount = fjPool.getRunningThreadCount(); // Returns an estimate of the number of worker threads that are not blocked waiting to join tasks or for other managed synchronization.
  int queuedSumbmissionCount = fjPool.getQueuedSubmissionCount(); // Returns an estimate of the number of tasks submitted to this pool that have not yet begun executing.
  long queuedTaskCount = fjPool.getQueuedTaskCount(); // Returns an estimate of the total number of tasks currently held in queues by worker threads (but not including tasks submitted to the pool that have not begun executing).
  long stealCount = fjPool.getStealCount(); //  Returns an estimate of the total number of tasks stolen from one thread's work queue by another.
  return new ForkJoinInfo(activeThreadCount, runningThreadCount, queuedSumbmissionCount, queuedTaskCount, stealCount);
}

代码示例来源:origin: com.arpnetworking.metrics.extras/jvm-extra

prefix,
        "active_threads"),
    executorService.getActiveThreadCount());
metrics.setGauge(
    String.join(

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

" activeThreads=" + pool.getActiveThreadCount() +
" runningThreads=" + pool.getRunningThreadCount() +
" poolSize=" + pool.getPoolSize() +

相关文章

微信公众号

最新文章

更多

ForkJoinPool类方法