Kryten Kryten - 6 months ago 28
Java Question

Get a List of all Threads currently running in Java

Is there any way I can get a list of all the running Threads in the current JVM (including the Threads NOT started by my class)?

Is it also possible to get the Thread and Class objects of all Thread in the list?

I want to be able to do this through code.


To get an iterable set:

Set<Thread> threadSet = Thread.getAllStackTraces().keySet();

To convert it to an array:

Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]);