java-单例模式的java连接池

 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();

 

posted @ 2015-07-24 18:06  MyCloud  阅读(804)  评论(0编辑  收藏  举报