Java Programs

Java Practice

Java program to print thread group Information

Java example to print thread group Information.
Submitted by Nidhi, on April 11, 2022

Problem statement

In this program, we will create a thread group using ThreadGroup class and add child threads to the group, and print thread group information using the list() method.

Source Code

The source code to print thread group Information is given below. The given program is compiled and executed successfully.

// Java program to print thread group Information

class MyThread extends Thread {
  MyThread(String threadname, ThreadGroup tg) {
    super(tg, threadname);
  public void run() {
    try {
      System.out.println(Thread.currentThread().getName() + " is finished");
    } catch (Exception e) {

public class Main {
  public static void main(String[] args) {
    try {
      ThreadGroup group = new ThreadGroup("Parent thread");

      MyThread t1 = new MyThread("Child Thread1", group);
      System.out.println(t1.getName() + " is started");

      MyThread t2 = new MyThread("Child Thread2", group);
      System.out.println(t2.getName() + " is started");


      System.out.println("\nThread Information: ");

    } catch (Exception e) {


Child Thread1 is started
Child Thread2 is started
Child Thread1 is finished
Child Thread2 is finished

Thread Information: 
java.lang.ThreadGroup[name=Parent thread,maxpri=10]


In the above program, we created two classes MyThread and Main. We created MyThread class by extending the Thread class.

The Main class contains a main() method. The main() method is the entry point for the program. Here, we created an object of ThreadGroup class and added the child thread into the thread group. After that, we printed group thread information using the list() method.

Java Threading Programs »

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.