Thread Showall
# Java Example - Get All Threads
[ Java Example](#)
The following example demonstrates how to use the getName() method to get all running threads:
## Main.java File
public class Main extends Thread{public static void main(String[]args){Main t1 = new Main(); t1.setName("thread1"); t1.start(); ThreadGroup currentGroup = Thread.currentThread().getThreadGroup(); int noThreads = currentGroup.activeCount(); Thread[]lstThreads = new Thread; currentGroup.enumerate(lstThreads); for(int i = 0; i<noThreads; i++)System.out.println("Thread numberοΌ" + i + " = " + lstThreads.getName()); }}
The output of the above code is:
Thread numberοΌ0 = main Thread numberοΌ1 = thread1
[ Java Example](#)
YouTip