YouTip LogoYouTip

Thread Showall

# Java Example - Get All Threads [![Image 3: Java Example](#) 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 [![Image 4: Java Example](#) Java Example](#)
← Collection RemoveCollection Conversion β†’