2012-01-12 72 views

回答

2
if (executor instanceof ThreadPoolExecutor) { 
    int poolSize = ((ThreadPoolExecutor) executor).getPoolSize(); 
    // or 
    int currentlyActive = ((ThreadPoolExecutor) executor).getActiveCount(); 
} 

但是总体来说,你应该知道,因为你已经构建服务(除非它隐藏在一些坏API)

+0

它可能只对newCachedThreadPool有用的()。 – Tudor 2012-01-12 22:50:36

+0

完美,谢谢。执行程序是使用'Executors.newFixedThreadPool(tpool)'生成的,我通常不知道它可以转换为ThreadPoolExecutor。很高兴知道! – OddProblems 2012-01-12 22:51:10