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 the setMaxPriority
method.
A thread group is weakly reachable from its parent group so that it is eligible for garbage collection when there are no live threads in the group and the thread group is otherwise unreachable.
Unless otherwise specified, passing a null
argument to a constructor
or method in this class will cause a NullPointerException
to be thrown.
Thread.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 the
setMaxPriority
method.
Virtual threads are not included in the estimated thread count returned by the
activeCount
method, are not enumerated by the enumerate
method, and are not interrupted by the interrupt
method.
API Note
Thread groups provided a way in early Java releases to group threads and provide a form of job 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.
Modifier and Type | Field and Description |
---|---|
private volatile boolean | |
private ThreadGroup[] | |
private volatile int | |
private final String | |
private int | |
private int | |
private final ThreadGroup | parent
All fields are accessed directly by the VM and from JVMTI functions. |
private WeakReference |
Access | Constructor and Description |
---|---|
private | |
pack-priv | ThreadGroup(ThreadGroup parent, String name, int maxPriority, boolean daemon)
Creates a ThreadGroup without any permission or other checks. |
private | |
public | |
public | ThreadGroup(ThreadGroup
the parent thread group. parent, String the name of the new thread group, can be name)null Creates a new thread group. |
Modifier and Type | Method and Description |
---|---|
public int | Returns: an estimate of the number of live threads in this thread group and in any other thread group that has this thread group as an ancestorReturns an estimate of the number of live platform threads in this thread group and its subgroups. |
public int | Returns: the number of thread groups with this thread group as an ancestorReturns an estimate of the number of groups in this thread group and its subgroups. |
public final void | checkAccess()
Deprecated
for removal since 17. This method is only useful in conjunction with
the Security Manager, which is
deprecated and subject to removal in a future release.
Determines if the currently running thread has permission to modify this thread group. |
private static Void | |
public final void | destroy()
Deprecated
for removal since 16. This method was originally specified to destroy an empty
thread group.
Does nothing. |
public int | |
public int | |
public int | Returns: the number of thread groups put into the arrayan array into which to put the list of thread groups list)Copies into the specified array references to every subgroup in this thread group and its subgroups. |
public int | Returns: the number of thread groups put into the arrayan array into which to put the list of thread groups list, boolean if recurse)true , recursively enumerate all subgroupsCopies into the specified array references to every subgroup in this thread group. |
private int | enumerate(ThreadGroup[] list, int i, boolean recurse)
Add a reference to each subgroup to the given array, starting at the given index. |
public final int | Returns: the maximum priority for new threads created in the thread groupReturns the maximum priority of this thread group. |
public final String | |
public final ThreadGroup | Returns: the parent of this thread group. The top-level thread group is the only thread group whose parent isnull .Returns the parent of this thread group. |
public final void | |
public final boolean | Returns: the daemon status of this thread group
Deprecated
for removal since 16. This method originally indicated if the thread group is a
daemon thread group that is automatically destroyed
when its last thread terminates.
Returns the daemon status of this thread group. |
public boolean | Returns: false
Deprecated
for removal since 16. This method originally indicated if the thread group is
destroyed.
Returns false. |
public void | |
private void | |
public final boolean | Returns: true if this thread group is the thread group
argument or one of its ancestor thread groups;
false otherwise.a thread group, can be g)null Tests if this thread group is either the thread group argument or one of its ancestor thread groups. |
private void | |
public final void | setDaemon(boolean
the daemon status daemon)
Deprecated
for removal since 16. This method originally configured whether the thread group is
a daemon thread group that is automatically destroyed
when its last thread terminates.
Sets the daemon status of this thread group. |
public final void | |
private List | |
private ThreadGroup[] | |
private void | |
private void | |
private List | |
public String | Returns: a string representation of this thread group.Overrides java. Returns a string representation of this Thread group. |
public void | uncaughtException(Thread
the thread that is about to exit. t, Throwable the uncaught exception. e)Implements java. Called by the Java Virtual Machine when a thread in this
thread group stops because of an uncaught exception, and the thread
does not have a specific |
daemon | back to summary |
---|---|
private volatile boolean daemon |
groups | back to summary |
---|---|
private ThreadGroup[] groups |
maxPriority | back to summary |
---|---|
private volatile int maxPriority |
name | back to summary |
---|---|
private final String name |
ngroups | back to summary |
---|---|
private int ngroups |
nweaks | back to summary |
---|---|
private int nweaks |
parent | back to summary |
---|---|
private final ThreadGroup parent All fields are accessed directly by the VM and from JVMTI functions. Operations that require synchronization on more than one group in the tree should synchronize on the parent group before synchronizing on the child group. |
weaks | back to summary |
---|---|
private WeakReference<ThreadGroup>[] weaks |
ThreadGroup | back to summary |
---|---|
private ThreadGroup() Creates the top-level "system" ThreadGroup. API Note This method is invoked by the VM early startup. |
ThreadGroup | back to summary |
---|---|
pack-priv ThreadGroup(ThreadGroup parent, String name, int maxPriority, boolean daemon) Creates a ThreadGroup without any permission or other checks. |
ThreadGroup | back to summary |
---|---|
private ThreadGroup(Void unused, ThreadGroup parent, String name) |
ThreadGroup | back to summary |
---|---|
public ThreadGroup(String name) Constructs a new thread group. The parent of this new group is the thread group of the currently running thread.
The
|
ThreadGroup | back to summary |
---|---|
public ThreadGroup(ThreadGroup parent, String name) Creates a new thread group. The parent of this new group is the specified thread group.
The
|
activeCount | back to summary |
---|---|
public int activeCount() Returns an estimate of the number of live platform threads in this thread group and its subgroups. Virtual threads are not included in the estimate. This method recursively iterates over all subgroups in this thread group. The value returned is only an estimate because the number of threads may change dynamically while this method traverses internal data structures, and might be affected by the presence of certain system threads. This method is intended primarily for debugging and monitoring purposes.
|
activeGroupCount | back to summary |
---|---|
public int activeGroupCount() Returns an estimate of the number of groups in this thread group and its subgroups. Recursively iterates over all subgroups in this thread group. The value returned is only an estimate because the number of thread groups may change dynamically while this method traverses internal data structures. This method is intended primarily for debugging and monitoring purposes.
|
checkAccess | back to summary |
---|---|
public final void checkAccess()
Deprecated for removal since 17. This method is only useful in conjunction with the Security Manager, which is deprecated and subject to removal in a future release. Consequently, this method is also deprecated and subject to removal. There is no replacement for the Security Manager or this method. Determines if the currently running thread has permission to modify this thread group.
If there is a security manager, its
|
checkParentAccess | back to summary |
---|---|
private static Void checkParentAccess(ThreadGroup parent) |
destroy | back to summary |
---|---|
public final void destroy()
Deprecated for removal since 16. This method was originally specified to destroy an empty thread group. The ability to explicitly destroy a thread group no longer exists. A thread group is eligible to be GC'ed when there are no live threads in the group and it is otherwise unreachable. Does nothing.
|
enumerate | back to summary |
---|---|
public int enumerate(Thread[] list) Copies into the specified array every live platform thread in this thread group and its subgroups. Virtual threads are not enumerated by this method. An invocation of this method behaves in exactly the same way as the invocation
enumerate
|
enumerate | back to summary |
---|---|
public int enumerate(Thread[] list, boolean recurse) Copies into the specified array every live
platform thread in this thread group. Virtual threads are not enumerated
by this method. If An application might use the activeCount
method to get an estimate of how big the array should be, however
if the array is too short to hold all the threads, the extra threads
are silently ignored. If it is critical to obtain every live
thread in this thread group, the caller should verify that the returned
int value is strictly less than the length of Due to the inherent race condition in this method, it is recommended that the method only be used for debugging and monitoring purposes.
|
enumerate | back to summary |
---|---|
public int enumerate(ThreadGroup[] list) Copies into the specified array references to every subgroup in this thread group and its subgroups. An invocation of this method behaves in exactly the same way as the invocation
enumerate
|
enumerate | back to summary |
---|---|
public int enumerate(ThreadGroup[] list, boolean recurse) Copies into the specified array references to every subgroup in this
thread group. If An application might use the
activeGroupCount method to
get an estimate of how big the array should be, however if the
array is too short to hold all the thread groups, the extra thread
groups are silently ignored. If it is critical to obtain every
subgroup in this thread group, the caller should verify that
the returned int value is strictly less than the length of
Due to the inherent race condition in this method, it is recommended that the method only be used for debugging and monitoring purposes.
|
enumerate | back to summary |
---|---|
private int enumerate(ThreadGroup[] list, int i, boolean recurse) Add a reference to each subgroup to the given array, starting at the given index. Returns the new index. |
getMaxPriority | back to summary |
---|---|
public final int getMaxPriority() Returns the maximum priority of this thread group. This is the maximum priority for new threads created in the thread group.
|
getName | back to summary |
---|---|
public final String getName() Returns the name of this thread group.
|
getParent | back to summary |
---|---|
public final ThreadGroup getParent() Returns the parent of this thread group.
First, if the parent is not
|
interrupt | back to summary |
---|---|
public final void interrupt() Interrupts all live platform threads in this thread group and its subgroups.
|
isDaemon | back to summary |
---|---|
public final boolean isDaemon()
Deprecated for removal since 16. This method originally indicated if the thread group is a daemon thread group that is automatically destroyed when its last thread terminates. The concept of daemon thread group no longer exists. A thread group is eligible to be GC'ed when there are no live threads in the group and it is otherwise unreachable. Returns the daemon status of this thread group. The daemon status is not used for anything.
|
isDestroyed | back to summary |
---|---|
public boolean isDestroyed()
Deprecated for removal since 16. This method originally indicated if the thread group is destroyed. The ability to destroy a thread group and the concept of a destroyed thread group no longer exists. A thread group is eligible to be GC'ed when there are no live threads in the group and it is otherwise unreachable. Returns false.
|
list | back to summary |
---|---|
public void list() Prints information about this thread group to the standard output. This method is useful only for debugging. |
list | back to summary |
---|---|
private void list(Map<ThreadGroup, List<Thread>> map, PrintStream out, int indent) |
parentOf | back to summary |
---|---|
public final boolean parentOf(ThreadGroup g) Tests if this thread group is either the thread group argument or one of its ancestor thread groups.
|
removeWeak | back to summary |
---|---|
private void removeWeak(int index) Remove the weakly reachable group at the given index of the weaks array. |
setDaemon | back to summary |
---|---|
public final void setDaemon(boolean daemon)
Deprecated for removal since 16. This method originally configured whether the thread group is a daemon thread group that is automatically destroyed when its last thread terminates. The concept of daemon thread group no longer exists. A thread group is eligible to be GC'ed when there are no live threads in the group and it is otherwise unreachable. Sets the daemon status of this thread group. The daemon status is not used for anything.
First, the
|
setMaxPriority | back to summary |
---|---|
public final void setMaxPriority(int pri) Sets the maximum priority of the group. The maximum priority of the ThreadGroup for virtual threads is not changed by this method (the new priority is ignored). Threads in the thread group (or subgroups) that already have a higher priority are not affected by this method.
First, the
If the
Otherwise, the priority of this ThreadGroup object is set to the
smaller of the specified
|
subgroups | back to summary |
---|---|
private List Returns a snapshot of the subgroups. |
subgroupsAsArray | back to summary |
---|---|
private ThreadGroup[] subgroupsAsArray() Returns a snapshot of the subgroups as an array, used by JVMTI. |
synchronizedAddStrong | back to summary |
---|---|
private void synchronizedAddStrong(ThreadGroup group) Add a strongly reachable subgroup. |
synchronizedAddWeak | back to summary |
---|---|
private void synchronizedAddWeak(ThreadGroup group) Add a weakly reachable subgroup. |
synchronizedSubgroups | back to summary |
---|---|
private List Returns a snapshot of the subgroups. |
toString | back to summary |
---|---|
public String toString() Overrides java. Returns a string representation of this Thread group.
|
uncaughtException | back to summary |
---|---|
public void uncaughtException(Thread t, Throwable e) Implements java. Called by the Java Virtual Machine when a thread in this
thread group stops because of an uncaught exception, and the thread
does not have a specific
The
Applications can override this method in subclasses of
|