/**
* @author lautturi.com
* Java example: how to get a list of all running threads in java
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
Thread[] arr = threadSet.toArray(new Thread[threadSet.size()]);
for (Thread thread : arr) {
System.out.println(thread.getId()+" "+thread.getName());
}
}
}
output:
3 Finalizer 5 Attach Listener 1 main 4 Signal Dispatcher 2 Reference Handler 11 Common-Cleaner