public class ThreadGroup extends Object implements Thread.UncaughtExceptionHandler
ThreadGroup is a means of organizing threads into a hierarchical structure.
This class is obsolete. See Effective Java Item 73, "Avoid thread groups" for details.Thread| Constructor and Description |
|---|
ThreadGroup(String name)
Constructs a new
ThreadGroup with the given name. |
ThreadGroup(ThreadGroup parent,
String name)
Constructs a new
ThreadGroup with the given name, as a child of the
given ThreadGroup. |
| Modifier and Type | Method and Description |
|---|---|
int |
activeCount()
Returns the number of running
Threads which are children of this thread group,
directly or indirectly. |
int |
activeGroupCount()
Returns the number of
ThreadGroups which are children of this group,
directly or indirectly. |
boolean |
allowThreadSuspension(boolean b)
Deprecated.
Required deprecated method suspend().
|
void |
checkAccess()
Does nothing.
|
void |
destroy()
Destroys this thread group and recursively all its subgroups.
|
int |
enumerate(Thread[] threads)
Iterates over all active threads in this group (and its sub-groups) and
stores the threads in the given array.
|
int |
enumerate(Thread[] threads,
boolean recurse)
Iterates over all active threads in this group (and, optionally, its
sub-groups) and stores the threads in the given array.
|
int |
enumerate(ThreadGroup[] groups)
Iterates over all thread groups in this group (and its sub-groups) and
and stores the groups in the given array.
|
int |
enumerate(ThreadGroup[] groups,
boolean recurse)
Iterates over all thread groups in this group (and, optionally, its
sub-groups) and stores the groups in the given array.
|
int |
getMaxPriority()
Returns the maximum allowed priority for a
Thread in this thread group. |
String |
getName()
Returns the name of this thread group.
|
ThreadGroup |
getParent()
Returns this thread group's parent
ThreadGroup. |
void |
interrupt()
Interrupts every
Thread in this group and recursively in all its
subgroups. |
boolean |
isDaemon()
Checks whether this thread group is a daemon
ThreadGroup. |
boolean |
isDestroyed()
Checks whether this thread group has already been destroyed.
|
void |
list()
Outputs to
System.out a text representation of the
hierarchy of Threads and ThreadGroups in this thread group (and recursively). |
boolean |
parentOf(ThreadGroup g)
Checks whether this thread group is a direct or indirect parent group of a
given
ThreadGroup. |
void |
resume()
Deprecated.
Requires deprecated method Thread.resume().
|
void |
setDaemon(boolean isDaemon)
Sets whether this is a daemon
ThreadGroup or not. |
void |
setMaxPriority(int newMax)
Configures the maximum allowed priority for a
Thread in this group and
recursively in all its subgroups. |
void |
stop()
Deprecated.
Requires deprecated method Thread.stop().
|
void |
suspend()
Deprecated.
Requires deprecated method Thread.suspend().
|
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
void |
uncaughtException(Thread t,
Throwable e)
Handles uncaught exceptions.
|
public ThreadGroup(String name)
ThreadGroup with the given name. The new ThreadGroup
will be child of the ThreadGroup to which the calling thread belongs.name - the nameThread.currentThread()public ThreadGroup(ThreadGroup parent, String name)
ThreadGroup with the given name, as a child of the
given ThreadGroup.parent - the parentname - the nameNullPointerException - if parent == nullIllegalThreadStateException - if parent has been
destroyed alreadypublic int activeCount()
Threads which are children of this thread group,
directly or indirectly.public int activeGroupCount()
ThreadGroups which are children of this group,
directly or indirectly.@Deprecated public boolean allowThreadSuspension(boolean b)
suspend(). The exact behavior of this call was never
specified.b - Used to control low memory implicit suspensiontrue (always)public final void checkAccess()
public final void destroy()
ThreadGroup that has no threads in it. Any daemon
ThreadGroup is destroyed automatically when it becomes empty (no threads
or thread groups in it).IllegalThreadStateException - if this thread group or any of its
subgroups has been destroyed already or if it still contains
threads.public int enumerate(Thread[] threads)
Note that this method will silently ignore any threads that don't fit in the supplied array.
threads - the array into which the Threads will be copiedThreads that were copiedpublic int enumerate(Thread[] threads, boolean recurse)
Note that this method will silently ignore any threads that don't fit in the supplied array.
threads - the array into which the Threads will be copiedrecurse - indicates whether Threads in subgroups should be
recursively copied as wellThreads that were copiedpublic int enumerate(ThreadGroup[] groups)
Note that this method will silently ignore any thread groups that don't fit in the supplied array.
groups - the array into which the ThreadGroups will be copiedThreadGroups that were copiedpublic int enumerate(ThreadGroup[] groups, boolean recurse)
Note that this method will silently ignore any thread groups that don't fit in the supplied array.
groups - the array into which the ThreadGroups will be copiedrecurse - indicates whether ThreadGroups in subgroups should be
recursively copied as well or notThreadGroups that were copiedpublic final int getMaxPriority()
Thread in this thread group.setMaxPriority(int)public final String getName()
public final ThreadGroup getParent()
ThreadGroup. It can be null if this
is the the root ThreadGroup.public final void interrupt()
Thread in this group and recursively in all its
subgroups.Thread.interrupt()public final boolean isDaemon()
ThreadGroup.ThreadGroupsetDaemon(boolean),
destroy()public boolean isDestroyed()
destroy()public void list()
System.out a text representation of the
hierarchy of Threads and ThreadGroups in this thread group (and recursively).
Proper indentation is used to show the nesting of groups inside groups
and threads inside groups.public final boolean parentOf(ThreadGroup g)
ThreadGroup.g - the potential child ThreadGroupg@Deprecated public final void resume()
Thread.resume(),
suspend()public final void setDaemon(boolean isDaemon)
ThreadGroup or not. Daemon
thread groups are automatically destroyed when they become empty.public final void setMaxPriority(int newMax)
Thread in this group and
recursively in all its subgroups.
A caller can never increase the maximum priority of a thread group. Such an attempt will not result in an exception, it will simply leave the thread group with its current maximum priority.
newMax - the new maximum priority to be setIllegalArgumentException - if the new priority is greater than
Thread.MAX_PRIORITY or less than Thread.MIN_PRIORITYgetMaxPriority()@Deprecated public final void stop()
Thread.stop(),
Thread.stop(Throwable),
ThreadDeath@Deprecated public final void suspend()
Thread.suspend(),
resume()public String toString()
ObjectgetClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString method
if you intend implementing your own toString method.
public void uncaughtException(Thread t, Throwable e)
Thread
is forwarded to the thread's ThreadGroup by invoking this
method.
New code should use Thread.setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) instead of thread groups.
uncaughtException in interface Thread.UncaughtExceptionHandlert - the Thread that terminated with an uncaught exceptione - the uncaught exception itself