Active threads in ExecutorService

后端 未结 6 1546
盖世英雄少女心
盖世英雄少女心 2020-12-23 19:16

Any ideas how to determine the number of active threads currently running in an ExecutorService?

6条回答
  •  没有蜡笔的小新
    2020-12-23 19:39

    Assuming pool is the name of the ExecutorService instance:

    if (pool instanceof ThreadPoolExecutor) {
        System.out.println(
            "Pool size is now " +
            ((ThreadPoolExecutor) pool).getActiveCount()
        );
    }
    

提交回复
热议问题