检查ExecutorService详细信息

时间:2012-01-12 22:34:16

标签: java executorservice

有没有办法深入了解ExecutorServer对象以查看当前使用了多少个线程?

1 个答案:

答案 0 :(得分:2)

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

但一般来说,你应该知道,因为你构建了服务(除非它隐藏在一些不好的API中)