A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/java/lang/thread_getthreadgroup.htm below:

Java Thread getThreadGroup() Method

Java Thread getThreadGroup() Method Description

The Java Thread getThreadGroup() method returns the thread group to which this thread belongs. It returns null if this thread has died (been stopped).

Declaration

Following is the declaration for java.lang.Thread.getThreadGroup() method

public final ThreadGroup getThreadGroup()
Parameters

NA

Return Value

This method returns this thread's thread group.

Exception

NA

Example: Getting ThreadGroup of a thread

The 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