1
有没有办法深入研究ExecutorServer
对象以查看当前正在使用多少个线程?检查执行程序服务详细信息
有没有办法深入研究ExecutorServer
对象以查看当前正在使用多少个线程?检查执行程序服务详细信息
if (executor instanceof ThreadPoolExecutor) {
int poolSize = ((ThreadPoolExecutor) executor).getPoolSize();
// or
int currentlyActive = ((ThreadPoolExecutor) executor).getActiveCount();
}
但是总体来说,你应该知道,因为你已经构建服务(除非它隐藏在一些坏API)
它可能只对newCachedThreadPool有用的()。 – Tudor 2012-01-12 22:50:36
完美,谢谢。执行程序是使用'Executors.newFixedThreadPool(tpool)'生成的,我通常不知道它可以转换为ThreadPoolExecutor。很高兴知道! – OddProblems 2012-01-12 22:51:10