![]() |
VOOZH | about |
Thread.activeCount() method is a static method of the Thread class in Java that returns the number of active threads in the current thread's thread group and its subgroups. It provides an estimate of how many threads are currently active and being executed in the program, including threads from any subgroups.
Example 1: Below is an example that demonstrates the usage of the Thread.activeCount() method.
Number of active threads: 3
Explanation:
public static int activeCount();
Example 2: In this example, we will use the Thread.activeCount() to check the number of active threads in a thread pool environment.
Initial: 1 Final: 3 Task 2 is starting. Task 1 is starting. Task 2 has finished. Task 1 has finished.
Explanation: