Get a list of all threads currently running in Java

Kryten picture Kryten · Aug 24, 2009 · Viewed 216.5k times · Source

Is there any way I can get a list of all 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 threads in the list?

I want to be able to do this through code.

Answer

thejoshwolfe picture thejoshwolfe · Jun 10, 2010

To get an iterable set:

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