The Java Thread getThreadGroup() method returns the thread group to which this thread belongs. It returns null if this thread has died (been stopped).
DeclarationFollowing is the declaration for java.lang.Thread.getThreadGroup() method
public final ThreadGroup getThreadGroup()Parameters
NA
Return ValueThis method returns this thread's thread group.
ExceptionNA
Example: Getting ThreadGroup of a threadThe following example shows the usage of Java Thread getThreadGroup() method. In this program, we've created a class ThreadDemo. In constructor, a new ThreadGroup is created along with a new thread using same threadgroup. Thread is started using start() method. In run() method, threadgroup is printed using getThreadGroup() method. In main method, ThreadDemo instance is created.
package com.tutorialspoint; 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(); } }Output
Let us compile and run the above program, this will produce the following result −
java.lang.ThreadGroup[name=Thread Group,maxpri=10]
java_lang_thread.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4