Java Data Type Tutorial - Java Thread.getThreadGroup()








Syntax

Thread.getThreadGroup() has the following syntax.

public final ThreadGroup getThreadGroup()

Example

In the following code shows how to use Thread.getThreadGroup() method.

class ThreadDemo extends Thread {
//from  www.  j a va  2s . c  o  m
  public void run() {
    // returns the thread group to which this thread belongs
    System.out.println(getThreadGroup());
  }
}

public class Main {

  public static void main(String[] args) {
    ThreadGroup tgrp = new ThreadGroup("Thread Group");
    Thread t = new Thread(tgrp, new ThreadDemo());
    t.start();
  }
}

The code above generates the following result.