How to get List of Java Threads



User Rating:  / 2
PoorBest 
Details
Category: Java
Created on Monday, 19 March 2012 09:46
Last Updated on Saturday, 12 May 2012 10:25
Published on Monday, 19 March 2012 09:46
Written by Administrator
Hits: 15741

The following code returns a list of Java Threads :

View source
package ListThreads;
 
import java.util.Set;
 
public class ListOfThreads {
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Set threadSet = Thread.getAllStackTraces().keySet();
         Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]);
         for(int i=0;i
             System.out.println(threadArray[i].getName().toString());
         }
    }
}