Java 查阅服务详情

Java 查阅服务详情,java,executorservice,Java,Executorservice,有没有一种方法可以深入查看ExecutorServer对象以查看当前使用了多少线程 if (executor instanceof ThreadPoolExecutor) { int poolSize = ((ThreadPoolExecutor) executor).getPoolSize(); // or int currentlyActive = ((ThreadPoolExecutor) executor).getActiveCount(); } 但一般来说,您

有没有一种方法可以深入查看
ExecutorServer
对象以查看当前使用了多少线程

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

但一般来说,您应该知道这一点,因为您已经构建了服务(除非它隐藏在一些糟糕的API中)

非常好,谢谢。执行器是使用
Executors.newFixedThreadPool(tpool)
生成的,我通常不知道它可以转换为ThreadPoolExecutor。很高兴知道!