get All Threads - Java java.lang

Java examples for java.lang:Thread

Description

get All Threads

Demo Code


//package com.java2s;
import java.util.Set;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(java.util.Arrays.toString(getAllThreads()));
    }//from  w w  w . j a  v a 2 s . co  m

    public static Thread[] getAllThreads() {
        Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
        Thread[] threads = threadSet.toArray(new Thread[threadSet.size()]);
        return threads;
    }
}

Related Tutorials