Java.lang.ThreadGroup.toString() Method


Advertisements


Description

The java.lang.ThreadGroup.toString() method returns a string representation of this Thread group.

Declaration

Following is the declaration for java.lang.ThreadGroup.toString() method

public String toString()

Parameters

NA

Return Value

This method returns a string representation of this thread group.

Exception

SecurityException − if the current thread cannot modify this thread group.

Example

The following example shows the usage of java.lang.ThreadGroup.toString() method.

package com.tutorialspoint;

import java.lang.*;

public class ThreadGroupDemo {

   public static void main(String[] args) {

      ThreadGroup group = new ThreadGroup("admin");
      Thread t = new Thread(group, "website");

      // prints threadGroup name
      System.out.println("Threadgroup = " + group.getName());

      // returns string representation of this Thread group
      String str = group.toString();
      System.out.println(str);
   }
} 

Let us compile and run the above program, this will produce the following result −

Threadgroup = admin
java.lang.ThreadGroup[name=admin,maxpri=10]

java_lang_threadgroup.htm

Advertisements