Java ThreadPoolExecutor getThreadPoolTrace(ThreadPoolExecutor threadpool)

Here you can find the source of getThreadPoolTrace(ThreadPoolExecutor threadpool)

Description

get Thread Pool Trace

License

Apache License

Declaration

public static String getThreadPoolTrace(ThreadPoolExecutor threadpool) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Main {

    public static String getThreadPoolTrace(ThreadPoolExecutor threadpool) {
        StringBuilder sb = new StringBuilder("thread pool: [");
        if (threadpool != null) {
            sb.append("\nactiveCount:").append(threadpool.getActiveCount());
            sb.append("\ncorePoolSize:").append(threadpool.getCorePoolSize());
            sb.append("\nlargetPoolSize:").append(threadpool.getLargestPoolSize());
            sb.append("\nmaximumPoolSize:").append(threadpool.getMaximumPoolSize());
            sb.append("\ntaskCount").append(threadpool.getTaskCount());
            sb.append("\nkeepAlive:").append(threadpool.getKeepAliveTime(TimeUnit.SECONDS));
            BlockingQueue<?> queue = threadpool.getQueue();
            if (queue != null) {
                sb.append("\nqueueSize:").append(queue.size());
            }/*from  w  ww.jav  a2s  . c om*/
            sb.append("\nstate:");
            if (threadpool.isShutdown()) {
                sb.append("shutdown");
            } else if (threadpool.isTerminated()) {
                sb.append("terminated");
            } else if (threadpool.isTerminating()) {
                sb.append("terminating");
            } else {
                sb.append("running");
            }
        } else {
            sb.append("\nnull");
        }
        sb.append("\n]");
        return sb.toString();
    }
}

Related

  1. executeInDaemon(Runnable... run)
  2. getBlockingWorkExecutor()
  3. getBoundedThreadPoolExecutor(int maxPoolSize, long keepAliveTime, TimeUnit unit, ThreadFactory tFactory)
  4. getScheduler()
  5. getThreadPoolExecutor(int poolSize, int[] poolInfo)
  6. getWorkerCount(ThreadPoolExecutor workerExecutor)
  7. parseRejectionPolicy(String rejection_policy)