1 package com.dawning.gridview.app.resourcemanagement.service.servicemanagement.discoverresourceutil;
 2 
 3 import java.util.concurrent.ExecutorService;
 4 import java.util.concurrent.Executors;
 5 
 6 /**
 7  * 线程池单例
 8  * @class SingletonTheadPool
 9  * @date 2015-7-7 下午3:29:04
10  * @author wanghc
11  */
12 public class SingletonTheadPool {
13     /**
14      * 单例
15      */
16     private static class SingletonHolder{
17         private static final ExecutorService MYPOOL = Executors.newFixedThreadPool(2);
18     }
19 
20     private SingletonTheadPool(){};
21 
22     public static final ExecutorService getSingletonTheadPool(){
23 
24         return SingletonHolder.MYPOOL;
25     }
26 
27 }

 // 获取当前线程池中活跃的线程数

将ExecutorService转换为ThreadPoolExecutor,ThreadPoolExecutor有方法 getActiveCount()可以得到当前活动线程数
int threadCount = ((ThreadPoolExecutor)MYPOOL).getActiveCount();

 

相关文章:

  • 2021-05-23
  • 2022-02-21
  • 2021-05-29
  • 2021-12-23
  • 2022-03-08
  • 2022-01-04
  • 2021-12-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2021-04-15
  • 2021-09-13
  • 2022-12-23
相关资源
相似解决方案