I\'m looking for a way to see the number of currently running threads
From Windows:
There's bound to be a performance counter for the process that can tell you that.
Programmatically:
There's Thread#activeCount:
Returns an estimate of the number of active threads in the current thread's thread group and its subgroups. Recursively iterates over all subgroups in the current thread's thread group.
Or more directly, ThreadGroup#activeCount:
Returns an estimate of the number of active threads in this thread group and its subgroups.
and ThreadGroup#getParent:
Returns the parent of this thread group.
First, if the parent is not null, the checkAccess method of the parent thread group is called with no arguments; this may result in a security exception.
All of which seem to suggest something along the lines of:
int activeThreadTotalEstimate() {
ThreadGroup group;
ThreadGroup parent;
group = Thread.currentThread().getThreadGroup();
while ((parent = group.getParent()) != null) {
group = parent;
}
return group.activeCount();
}