How to get List of Java Threads
Details
- 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: 18554
The following code returns a list of Java Threads :
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());
}
}
}