Java Thread activeCount() 方法

2025年3月21日 | 阅读 1 分钟

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

语法

返回

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

示例

输出

number of active thread: 2
running thread name is: Thread-1
running thread name is: Thread-2
 
下一主题Java 多线程