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 }

 // 獲取當前線程池中活躍的線程數java

將ExecutorService轉換爲ThreadPoolExecutor,ThreadPoolExecutor有方法 getActiveCount()能夠獲得當前活動線程數
int threadCount = ((ThreadPoolExecutor)MYPOOL).getActiveCount();app

相關文章
相關標籤/搜索