2012-01-12 36 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