Module java.base
Package java.lang

Class ThreadGroup

java.lang.Object
java.lang.ThreadGroup
All Implemented Interfaces:
Thread.UncaughtExceptionHandler

public classThreadGroupextendsObjectimplementsThread.UncaughtExceptionHandler
A thread group represents a set of threads. In addition, a thread group can also include other thread groups. The thread groups form a tree in which every thread group except the initial thread group has a parent.

A thread group has a name and maximum priority. The name is specified when creating the group and cannot be changed. The group's maximum priority is the maximum priority for threads created in the group. It is initially inherited from the parent thread group but may be changed using thesetMaxPriority method.

A thread group is weaklyreachable from its parent group so that it is eligible for garbage collection when there are nolive threads in the group and the thread group is otherwiseunreachable.

Unless otherwise specified, passing anull argument to a constructor or method in this class will cause aNullPointerException to be thrown.

Thread groups and virtual threads

The Java runtime creates a special thread group forvirtual threads. This group is returned by theThread.getThreadGroup method when invoked on a virtual thread. The thread group differs to other thread groups in that its maximum priority is fixed and cannot be changed with thesetMaxPriority method. Virtual threads are not included in the estimated thread count returned by theactiveCount method, are not enumerated by theenumerate method, and are not interrupted by theinterrupt method.
API Note:
Thread groups provided a way in early Java releases to group threads and provide a form ofjob control for threads. Thread groups supported the isolation of applets and defined methods intended for diagnostic purposes. It should be rare for new applications to create ThreadGroups and interact with this API.
Since:
1.0