java.lang.Object | |
↳ | java.lang.ThreadGroup |
A ThreadGroup
is a means of organizing Thread
s into a
hierarchical structure. A ThreadGroup
can contain zero or more
Thread
s and zero or more other ThreadGroup
s. Each Thread
and each ThreadGroup
(except the root group) has a unique
parent ThreadGroup
. The result is a tree whose inner nodes are
ThreadGroup
s and whose leaf nodes are Threads
. The unique
root of the tree is a ThreadGroup
that is created at VM startup and
has the name "system". The benefit of using ThreadGroup
s, in addition
to the mere housekeeping aspect, is that all Thread
s in a ThreadGroup
can be manipulated together, that is, the ThreadGroup
has methods that delegate to all its all Thread
s.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new ThreadGroup with the name provided.
| |||||||||||
Constructs a new ThreadGroup with the name provided, as child of the
ThreadGroup
parent . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the number of Threads which are children of the receiver,
directly or indirectly and are running.
| |||||||||||
Returns the number of ThreadGroups which are children of the receiver,
directly or indirectly.
| |||||||||||
This method is deprecated.
Required deprecated method suspend().
| |||||||||||
Checks the accessibility of the ThreadGroup from the perspective of the
caller.
| |||||||||||
Destroys the receiver and recursively all its subgroups.
| |||||||||||
Iterates over all thread groups in this group (and its sub-groups) and
and stores the groups in the given array.
| |||||||||||
Iterates over all thread groups in this group (and, optionally, its
sub-groups) and and stores the groups in the given array.
| |||||||||||
Iterates over all active threads in this group (and, optionally, its
sub-groups) and stores the threads in the given array.
| |||||||||||
Iterates over all active threads in this group (and its sub-groups) and
stores the threads in the given array.
| |||||||||||
Returns the maximum allowed priority for a Thread in the receiver.
| |||||||||||
Returns the name of the receiver.
| |||||||||||
Returns the receiver's parent ThreadGroup.
| |||||||||||
Interrupts every Thread in the receiver and recursively in all its
subgroups.
| |||||||||||
Checks whether the receiver is a daemon ThreadGroup.
| |||||||||||
Checks whether the receiver has already been destroyed.
| |||||||||||
Outputs to
System.out a text representation of the
hierarchy of Threads and ThreadGroups in the receiver (and recursively). | |||||||||||
Checks whether the receiver is a direct or indirect parent group of a
given ThreadGroup.
| |||||||||||
This method is deprecated.
Requires deprecated method Thread.resume().
| |||||||||||
Configures the receiver to be a daemon ThreadGroup or not.
| |||||||||||
Configures the maximum allowed priority for a Thread in the receiver and
recursively in all its subgroups.
| |||||||||||
This method is deprecated.
Requires deprecated method Thread.stop().
| |||||||||||
This method is deprecated.
Requires deprecated method Thread.suspend().
| |||||||||||
Returns a string containing a concise, human-readable description of the
receiver.
| |||||||||||
Handles uncaught exceptions.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
| |||||||||||
From interface java.lang.Thread.UncaughtExceptionHandler
|
Constructs a new ThreadGroup with the name provided. The new ThreadGroup
will be child of the ThreadGroup to which the
Thread.currentThread()
belongs.
name | the name for the ThreadGroup being created |
---|
SecurityException | if checkAccess() for the parent
group fails with a SecurityException |
---|
Constructs a new ThreadGroup with the name provided, as child of the
ThreadGroup parent
.
parent | the parent ThreadGroup |
---|---|
name | the name for the ThreadGroup being created |
NullPointerException | if parent is
null |
---|---|
SecurityException | if checkAccess() for the parent
group fails with a SecurityException |
IllegalThreadStateException | if parent has been
destroyed already
|
Returns the number of Threads which are children of the receiver, directly or indirectly and are running.
Returns the number of ThreadGroups which are children of the receiver, directly or indirectly.
This method is deprecated.
Required deprecated method suspend().
Does nothing. The definition of this method depends on the deprecated
method suspend()
. The exact behavior of this call was never
specified.
b | Used to control low memory implicit suspension |
---|
true
(always)Checks the accessibility of the ThreadGroup from the perspective of the
caller. If there is a SecurityManager installed, calls
checkAccess
with the receiver as a parameter, otherwise does
nothing.
Destroys the receiver and recursively all its subgroups. It is only legal to destroy a ThreadGroup that has no Threads in it. Any daemon ThreadGroup is destroyed automatically when it becomes empty (no Threads and no ThreadGroups in it).
IllegalThreadStateException | if the receiver or any of its subgroups has been destroyed already or if it still contains threads. |
---|---|
SecurityException | if this.checkAccess() fails with
a SecurityException
|
Iterates over all thread groups in this group (and its sub-groups) and and stores the groups in the given array. Returns when the array is full or no more groups remain, whichever happens first.
groups | the array into which the ThreadGroups will be copied |
---|
Iterates over all thread groups in this group (and, optionally, its sub-groups) and and stores the groups in the given array. Returns when the array is full or no more groups remain, whichever happens first.
groups | the array into which the ThreadGroups will be copied |
---|---|
recurse | indicates whether ThreadGroups in subgroups should be recursively copied as well or not |
Iterates over all active threads in this group (and, optionally, its sub-groups) and stores the threads in the given array. Returns when the array is full or no more threads remain, whichever happens first.
threads | the array into which the Threads will be copied |
---|---|
recurse | indicates whether Threads in subgroups should be recursively copied as well |
Iterates over all active threads in this group (and its sub-groups) and stores the threads in the given array. Returns when the array is full or no more threads remain, whichever happens first.
threads | the array into which the Threads will be copied |
---|
Returns the maximum allowed priority for a Thread in the receiver.
Returns the name of the receiver.
Returns the receiver's parent ThreadGroup. It can be null
if the
receiver is the the root ThreadGroup.
Interrupts every Thread in the receiver and recursively in all its subgroups.
SecurityException | if this.checkAccess() fails with
a SecurityException |
---|
Checks whether the receiver is a daemon ThreadGroup.
Checks whether the receiver has already been destroyed.
Outputs to System.out
a text representation of the
hierarchy of Threads and ThreadGroups in the receiver (and recursively).
Proper indentation is done to suggest the nesting of groups inside groups
and threads inside groups.
Checks whether the receiver is a direct or indirect parent group of a given ThreadGroup.
g | the potential child ThreadGroup |
---|
g
This method is deprecated.
Requires deprecated method Thread.resume().
Resumes every Thread in the receiver and recursively in all its subgroups.
SecurityException | if this.checkAccess() fails with
a SecurityException |
---|
Configures the receiver to be a daemon ThreadGroup or not. Daemon ThreadGroups are automatically destroyed when they become empty.
isDaemon | the new value defining if receiver should be daemon or not |
---|
SecurityException | if checkAccess() for the parent
group fails with a SecurityException |
---|
Configures the maximum allowed priority for a Thread in the receiver and recursively in all its subgroups. One can never change the maximum priority of a ThreadGroup to be higher than it was. Such an attempt will not result in an exception, it will simply leave the ThreadGroup with its current maximum priority.
newMax | the new maximum priority to be set |
---|
SecurityException | if checkAccess() fails with a
SecurityException |
---|---|
IllegalArgumentException | if the new priority is greater than Thread.MAX_PRIORITY or less than Thread.MIN_PRIORITY |
This method is deprecated.
Requires deprecated method Thread.stop().
Stops every Thread in the receiver and recursively in all its subgroups.
SecurityException | if this.checkAccess() fails with
a SecurityException |
---|
This method is deprecated.
Requires deprecated method Thread.suspend().
Suspends every Thread in the receiver and recursively in all its subgroups.
SecurityException | if this.checkAccess() fails with
a SecurityException |
---|
Returns a string containing a concise, human-readable description of the receiver.
Handles uncaught exceptions. Any uncaught exception in any Thread is forwarded (by the VM) to the Thread's ThreadGroup by sending this message (uncaughtException). This allows users to define custom ThreadGroup classes and custom behavior for when a Thread has an uncaughtException or when it does (ThreadDeath).
t | the Thread that terminated with an uncaught exception |
---|---|
e | the uncaught exception itself |