get All Thread Names - Java java.lang

Java examples for java.lang:Thread

Description

get All Thread Names

Demo Code

/**// w ww  .j a v a  2  s  .c  o  m
 * Project: richContentMediaSearchService
 * ROLE-Project
 * authors: daniel.dahrendorf@im-c.de, julian.weber@im-c.de
 * This software uses the GNU GPL   
 */
//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getAllThreadNames());
    }

    public static String getAllThreadNames() {
        Thread[] array = new Thread[Thread.activeCount()];

        Thread.enumerate(array);

        String s = "";
        for (Thread t : array) {
            if (t != null) {
                s += t.getName() + ", ";
            }
        }
        return s;
    }
}

Related Tutorials