示例#1
0
 public ThreadPoolStats stats() {
   List<ThreadPoolStats.Stats> stats = new ArrayList<ThreadPoolStats.Stats>();
   for (ExecutorHolder holder : executors.values()) {
     String name = holder.info.getName();
     // no need to have info on "same" thread pool
     if ("same".equals(name)) {
       continue;
     }
     int threads = -1;
     int queue = -1;
     int active = -1;
     long rejected = -1;
     int largest = -1;
     long completed = -1;
     if (holder.executor instanceof ThreadPoolExecutor) {
       ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) holder.executor;
       threads = threadPoolExecutor.getPoolSize();
       queue = threadPoolExecutor.getQueue().size();
       active = threadPoolExecutor.getActiveCount();
       largest = threadPoolExecutor.getLargestPoolSize();
       completed = threadPoolExecutor.getCompletedTaskCount();
       RejectedExecutionHandler rejectedExecutionHandler =
           threadPoolExecutor.getRejectedExecutionHandler();
       if (rejectedExecutionHandler instanceof XRejectedExecutionHandler) {
         rejected = ((XRejectedExecutionHandler) rejectedExecutionHandler).rejected();
       }
     }
     stats.add(
         new ThreadPoolStats.Stats(name, threads, queue, active, rejected, largest, completed));
   }
   return new ThreadPoolStats(stats);
 }
 public long getTaskCount() {
   return (executorService_.getTaskCount() - executorService_.getCompletedTaskCount());
 }