Add thread to thread group : ThreadGroup « Thread « Java Tutorial






class ThreadGroupDemo1 {
  public static void main(String[] args) {
    ThreadGroup tg = new ThreadGroup("My ThreadGroup");

    MyThread mt = new MyThread(tg, "My Thread");
    mt.start();
  }
}

class MyThread extends Thread {
  MyThread(ThreadGroup tg, String name) {
    super(tg, name);
  }

  public void run() {
    ThreadGroup tg = getThreadGroup();
    System.out.println(tg.getName());
  }
}








10.6.ThreadGroup
10.6.1.Demonstrate thread groups.
10.6.2.Add thread to thread group
10.6.3.Get parent thread group
10.6.4.Listing all threads and threadgroups in the VM