java.lang.Object
java.lang.ThreadGroup
- All Implemented Interfaces:
Thread.UncaughtExceptionHandler
ThreadGroups are containers of Threads and ThreadGroups, therefore providing
a tree-like structure to organize Threads. The root ThreadGroup name is "system"
and it has no parent ThreadGroup. All other ThreadGroups have exactly one parent
ThreadGroup. All Threads belong to exactly one ThreadGroup.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionThreadGroup(String name) Constructs a new ThreadGroup with the name provided.ThreadGroup(ThreadGroup parent, String name) Constructs a new ThreadGroup with the name provided, as child of the ThreadGroupparent -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of Threads which are children of the receiver, directly or indirectly.intReturns the number of ThreadGroups which are children of the receiver, directly or indirectly.booleanallowThreadSuspension(boolean b) Deprecated, for removal: This API element is subject to removal in a future version.Required deprecated method suspend().final voidDeprecated, for removal: This API element is subject to removal in a future version.final voiddestroy()Deprecated, for removal: This API element is subject to removal in a future version.intCopies an array with all Threads which are children of the receiver (directly or indirectly) into the arraythreadspassed as parameters.intCopies an array with all Threads which are children of the receiver into the arraythreadspassed as parameter.intenumerate(ThreadGroup[] groups) Copies an array with all ThreadGroups which are children of the receiver (directly or indirectly) into the arraygroupspassed as parameters.intenumerate(ThreadGroup[] groups, boolean recurse) Copies an array with all ThreadGroups which are children of the receiver into the arraygroupspassed as parameter.final intAnswers the maximum allowed priority for a Thread in the receiver.final StringgetName()Answers the name of the receiver.final ThreadGroupAnswers the receiver's parent ThreadGroup.final voidInterrupts every Thread in the receiver and recursively in all its subgroups.final booleanisDaemon()Deprecated, for removal: This API element is subject to removal in a future version.booleanDeprecated, for removal: This API element is subject to removal in a future version.voidlist()Outputs toSystem.outa text representation of the hierarchy of Threads and ThreadGroups in the receiver (and recursively).final booleanAnswers true if the receiver is a direct or indirect parent group of ThreadGroupg, false otherwise.final voidresume()Deprecated, for removal: This API element is subject to removal in a future version.Requires deprecated method Thread.resume().final voidsetDaemon(boolean isDaemon) Deprecated, for removal: This API element is subject to removal in a future version.final voidsetMaxPriority(int newMax) Configures the maximum allowed priority for a Thread in the receiver and recursively in all its subgroups.final voidstop()Deprecated, for removal: This API element is subject to removal in a future version.Requires deprecated method Thread.stop().final voidsuspend()Deprecated, for removal: This API element is subject to removal in a future version.Requires deprecated method Thread.suspend().toString()Answers a string containing a concise, human-readable description of the receiver.voiduncaughtException(Thread t, Throwable e) Any uncaught exception in any Thread has to be forwarded (by the VM) to the Thread's ThreadGroup by sending this message (uncaughtException).
-
Constructor Details
-
ThreadGroup
Constructs a new ThreadGroup with the name provided. The new ThreadGroup will be child of the ThreadGroup to which theThread.currentThread()belongs.- Parameters:
name- Name for the ThreadGroup being created- Throws:
SecurityException- ifcheckAccess()for the parent group fails with a SecurityException- See Also:
-
ThreadGroup
Constructs a new ThreadGroup with the name provided, as child of the ThreadGroupparent- Parameters:
parent- Parent ThreadGroupname- Name for the ThreadGroup being created- Throws:
NullPointerException- ifparentisnullSecurityException- ifcheckAccess()for the parent group fails with a SecurityExceptionIllegalThreadStateException- ifparenthas been destroyed already
-
-
Method Details
-
activeCount
public int activeCount()Returns the number of Threads which are children of the receiver, directly or indirectly.- Returns:
- Number of children Threads
-
activeGroupCount
public int activeGroupCount()Returns the number of ThreadGroups which are children of the receiver, directly or indirectly.- Returns:
- Number of children ThreadGroups
-
allowThreadSuspension
Deprecated, for removal: This API element is subject to removal in a future version.Required deprecated method suspend().The definition of this method depends on the deprecated methodsuspend(). The behavior of this call was never specified.- Parameters:
b- Used to control low memory implicit suspension- Returns:
- always returns true
-
checkAccess
Deprecated, for removal: This API element is subject to removal in a future version.If there is a SecurityManager installed, callcheckAccessin it passing the receiver as parameter, otherwise do nothing. -
destroy
Deprecated, for removal: This API element is subject to removal in a future version.Destroys the receiver and recursively all its subgroups. It is only legal to destroy a ThreadGroup that has no Threads. Any daemon ThreadGroup is destroyed automatically when it becomes empty (no Threads and no ThreadGroups in it).- Throws:
IllegalThreadStateException- if the receiver or any of its subgroups has been destroyed alreadySecurityException- ifthis.checkAccess()fails with a SecurityException
-
enumerate
Copies an array with all Threads which are children of the receiver (directly or indirectly) into the arraythreadspassed as parameters. If the array passed as parameter is too small no exception is thrown - the extra elements are simply not copied.- Parameters:
threads- Thread array into which the Threads will be copied- Returns:
- How many Threads were copied over
-
enumerate
Copies an array with all Threads which are children of the receiver into the arraythreadspassed as parameter. Children Threads of subgroups are recursively copied as well if parameterrecurseistrue. If the array passed as parameter is too small no exception is thrown - the extra elements are simply not copied.- Parameters:
threads- array into which the Threads will be copiedrecurse- Indicates whether Threads in subgroups should be recursively copied as well or not- Returns:
- How many Threads were copied over
-
enumerate
Copies an array with all ThreadGroups which are children of the receiver (directly or indirectly) into the arraygroupspassed as parameters. If the array passed as parameter is too small no exception is thrown - the extra elements are simply not copied.- Parameters:
groups- array into which the ThreadGroups will be copied- Returns:
- How many ThreadGroups were copied over
-
enumerate
Copies an array with all ThreadGroups which are children of the receiver into the arraygroupspassed as parameter. Children ThreadGroups of subgroups are recursively copied as well if parameterrecurseistrue. If the array passed as parameter is too small no exception is thrown - the extra elements are simply not copied.- Parameters:
groups- array into which the ThreadGroups will be copiedrecurse- Indicates whether ThreadGroups in subgroups should be recursively copied as well or not- Returns:
- How many ThreadGroups were copied over
-
getMaxPriority
public final int getMaxPriority()Answers the maximum allowed priority for a Thread in the receiver.- Returns:
- the maximum priority (an
int) - See Also:
-
getName
Answers the name of the receiver.- Returns:
- the receiver's name (a java.lang.String)
-
getParent
Answers the receiver's parent ThreadGroup. It can be null if the receiver is the root ThreadGroup.- Returns:
- the parent ThreadGroup
-
interrupt
public final void interrupt()Interrupts every Thread in the receiver and recursively in all its subgroups.- Throws:
SecurityException- ifthis.checkAccess()fails with a SecurityException- See Also:
-
isDaemon
Deprecated, for removal: This API element is subject to removal in a future version.Answers true if the receiver is a daemon ThreadGroup, false otherwise.- Returns:
- if the receiver is a daemon ThreadGroup
- See Also:
-
isDestroyed
Deprecated, for removal: This API element is subject to removal in a future version.Answers true if the receiver has been destroyed already, false otherwise.- Returns:
- if the receiver has been destroyed already
- See Also:
-
list
public void list()Outputs toSystem.outa 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. -
parentOf
Answers true if the receiver is a direct or indirect parent group of ThreadGroupg, false otherwise.- Parameters:
g- ThreadGroup to test- Returns:
- if the receiver is parent of the ThreadGroup passed as parameter
-
resume
Deprecated, for removal: This API element is subject to removal in a future version.Requires deprecated method Thread.resume().Resumes every Thread in the receiver and recursively in all its subgroups.- Throws:
SecurityException- ifthis.checkAccess()fails with a SecurityException- See Also:
-
setDaemon
Deprecated, for removal: This API element is subject to removal in a future version.Configures the receiver to be a daemon ThreadGroup or not. Daemon ThreadGroups are automatically destroyed when they become empty.- Parameters:
isDaemon- new value defining if receiver should be daemon or not- Throws:
SecurityException- ifcheckAccess()for the parent group fails with a SecurityException- See Also:
-
isDaemondestroy()
-
setMaxPriority
public final void setMaxPriority(int newMax) 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.- Parameters:
newMax- the new maximum priority to be set- Throws:
SecurityException- ifcheckAccess()fails with a SecurityExceptionIllegalArgumentException- if the new priority is greater than Thread.MAX_PRIORITY or less than Thread.MIN_PRIORITY- See Also:
-
stop
Deprecated, for removal: This API element is subject to removal in a future version.Requires deprecated method Thread.stop().Stops every Thread in the receiver and recursively in all its subgroups.- Throws:
SecurityException- ifthis.checkAccess()fails with a SecurityException- See Also:
-
suspend
Deprecated, for removal: This API element is subject to removal in a future version.Requires deprecated method Thread.suspend().Suspends every Thread in the receiver and recursively in all its subgroups.- Throws:
SecurityException- ifthis.checkAccess()fails with a SecurityException- See Also:
-
toString
Answers a string containing a concise, human-readable description of the receiver. -
uncaughtException
Any uncaught exception in any Thread has to be 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).- Specified by:
uncaughtExceptionin interfaceThread.UncaughtExceptionHandler- Parameters:
t- Thread with an uncaught exceptione- The uncaught exception itself- See Also:
-