Home » Java Thread getThreadGroup() Method with Examples

Java Thread getThreadGroup() Method with Examples

by Online Tutorials Library

Java Thread getThreadGroup() method

The getThreadGroup() method of thread class is used to return the thread’s thread group to which this thread belongs. This method returns null if this thread has died (been stopped).

Syntax

Return

This method returns the thread group of the thread.

Example

Test it Now

Output:

Thread-1 is a member of ThreadGroup  Thread-2 is a member of AnotherGroup TutorAspire tutoraspire  

The above example use getThreadGroup() method of Thread class to get the object of ThreadGroup then use the getName() method to get the name of the thread group.

You may also like