A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/javaexamples/thread_showall.htm below:

How to display all running Thread in Java

How to display all running Thread in Java Problem Description

How to display all running Thread?

Solution

Following example demonstrates how to display names of all the running threads using getName() method.

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[noThreads];
      currentGroup.enumerate(lstThreads);
      
      for (int i = 0; i < noThreads; i++) System.out.println("Thread No:" + i + " = " + lstThreads[i].getName());
   }
}
Result

The above code sample will produce the following result.

Thread No:0 = main
Thread No:1 = thread1

java_threading.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4