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