使用场景:

 对于多线程业务, 为了避免OOM ,  需要手动控制线程数, 这时,需要获取当前活跃的线程数,  已做控制

/将exes转换为ThreadPoolExecutor,ThreadPoolExecutor有方法 getActiveCount()可以得到当前活动线程数

   

eg:

   ExecutorService exes= Executors.newFixedThreadPool(10);

    int threadCount = ((ThreadPoolExecutor)exes).getActiveCount();

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
  • 2021-12-27
  • 2022-03-07
猜你喜欢
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-08
  • 2021-10-06
  • 2021-09-10
相关资源
相似解决方案