A thread group represents a set of threads. In addition, a thread group can also include other thread groups. The thread groups form a tree in which every thread group except the initial thread group has a parent.

A thread is allowed to access information about its own thread group, but not to access information about its thread group’s parent thread group or any other thread groups.

Syntax :

public class ThreadGroup extends Object

Constructor Summary :

ThreadGroup(String name)

Constructs a new thread group.

ThreadGroup(ThreadGroup parent, String name)

Creates a new thread group

Click Here to get complete list of Methods associated with ThreadGroup

Quick Example to Show ThreadGroup :

class MyThread extends Thread {
  boolean stopped;

  MyThread(ThreadGroup tg, String name) {
    super(tg, name);
    stopped = false;

  public void run() {
    System.out.println(Thread.currentThread().getName() ” starting.”);
    try {
      for (int i = 1; i < 1000; i++) {
        synchronized (this) {
          if (stopped)
    catch (Exception exc) {
      System.out.println(Thread.currentThread().getName() ” interrupted.”);
    System.out.println(Thread.currentThread().getName() ” exiting.”);

  synchronized void myStop() {
    stopped = true;

public class Main {
  public static void main(String args[]) throws Exception {
    ThreadGroup tg = new ThreadGroup(“My Group”);

    MyThread thrd = new MyThread(tg, “MyThread #1”);
    MyThread thrd2 = new MyThread(tg, “MyThread #2”);
    MyThread thrd3 = new MyThread(tg, “MyThread #3”);



    System.out.println(tg.activeCount() ” threads in thread group.”);

    Thread thrds[] new Thread[tg.activeCount()];
    for (Thread t : thrds)


    System.out.println(tg.activeCount() ” threads in tg.”);