2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Get a List of all Threads currently running in Java

In my application several threads are executed dynamically because of which its difficult to find out that how may threads are running in a current instance of time.

Is there any way to find the list of current threads.

userimage
List out the thread stack,

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


And then convert it to an array:

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

Answer is