Java ThreadGroup activeCount() 方法

2024 年 11 月 11 日 | 阅读 1 分钟

ThreadGroup 类的 activeCount() 方法用于返回当前线程的线程组中活动的线程数。返回的值仅为估计值,因为在方法遍历内部数据结构时,线程数可能会动态变化。

语法

返回

它返回当前线程所在线程组中的活动线程数。

示例

输出

Number of active thread: 3
Thread-1 completed executing
Thread-2 completed executing
Thread-3 completed executing