I want to know how many active threads are there for a particular Thread class. Lets say I have a class T which extends thread. In some other class (Ex: Demo) , I want to get t
private static int getThreadCount(){
int runningThread = 0;
for (Thread t : Thread.getAllStackTraces().keySet()) if (t.getState()==Thread.State.RUNNABLE && t instanceof YourThreadClassName ) runningThread++;
System.out.println("Active threads : "+runningThread);
return runningThread;
}
Justreplace YourThreadClassName with your class that is extended by Thread.