目录

ThreadGroup getThreadGroup()

描述 (Description)

java.lang.Thread.getThreadGroup()方法返回此线程所属的线程组。 如果此线程已死(已停止),则返回null。

声明 (Declaration)

以下是java.lang.Thread.getThreadGroup()方法的声明

public final ThreadGroup getThreadGroup()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回此线程的线程组。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.lang.Thread.getThreadGroup()方法的用法。

package com.iowiki;
import java.lang.*;
public class ThreadDemo implements Runnable {
   Thread t;
   ThreadGroup tgrp;
   ThreadDemo() {
      tgrp = new ThreadGroup("Thread Group");
      t = new Thread(tgrp, this);
      t.start();
   }
   public void run() {
      // returns the thread group to which this thread belongs
      System.out.println(t.getThreadGroup());
   }
   public static void main(String[] args) {
      new ThreadDemo();
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

java.lang.ThreadGroup[name=Thread Group,maxpri=10]
↑回到顶部↑
WIKI教程 @2018