Skip to content

Most visited

Recently visited

navigation
Added in API level 1

ThreadGroup

public class ThreadGroup
extends Object implements Thread.UncaughtExceptionHandler

java.lang.Object
   ↳ java.lang.ThreadGroup


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.

See also:

Summary

Public constructors

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.

Public methods

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)

This method was deprecated in API level 1. Required deprecated method suspend().

final void checkAccess()

Does nothing.

final 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(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 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.

final int getMaxPriority()

Returns the maximum allowed priority for a Thread in this thread group.

final String getName()

Returns the name of this thread group.

final ThreadGroup getParent()

Returns this thread group's parent ThreadGroup.

final void interrupt()

Interrupts every Thread in this group and recursively in all its subgroups.

final 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).

final boolean parentOf(ThreadGroup g)

Checks whether this thread group is a direct or indirect parent group of a given ThreadGroup.

final void resume()

This method was deprecated in API level 1. Requires deprecated method Thread.resume().

final void setDaemon(boolean isDaemon)

Sets whether this is a daemon ThreadGroup or not.

final void setMaxPriority(int newMax)

Configures the maximum allowed priority for a Thread in this group and recursively in all its subgroups.

final void stop()

This method was deprecated in API level 1. Requires deprecated method Thread.stop().

final void suspend()

This method was deprecated in API level 1. 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.

Inherited methods

From class java.lang.Object
From interface java.lang.Thread.UncaughtExceptionHandler

Public constructors

ThreadGroup

Added in API level 1
ThreadGroup (String name)

Constructs a new ThreadGroup with the given name. The new ThreadGroup will be child of the ThreadGroup to which the calling thread belongs.

Parameters
name String: the name

See also:

ThreadGroup

Added in API level 1
ThreadGroup (ThreadGroup parent, 
                String name)

Constructs a new ThreadGroup with the given name, as a child of the given ThreadGroup.

Parameters
parent ThreadGroup: the parent
name String: the name
Throws
NullPointerException if parent == null
IllegalThreadStateException if parent has been destroyed already

Public methods

activeCount

Added in API level 1
int activeCount ()

Returns the number of running Threads which are children of this thread group, directly or indirectly.

Returns
int the number of children

activeGroupCount

Added in API level 1
int activeGroupCount ()

Returns the number of ThreadGroups which are children of this group, directly or indirectly.

Returns
int the number of children

allowThreadSuspension

Added in API level 1
boolean allowThreadSuspension (boolean b)

This method was deprecated in API level 1.
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.

Parameters
b boolean: Used to control low memory implicit suspension
Returns
boolean true (always)

checkAccess

Added in API level 1
void checkAccess ()

Does nothing.

destroy

Added in API level 1
void destroy ()

Destroys this thread group 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 or thread groups in it).

Throws
IllegalThreadStateException if this thread group or any of its subgroups has been destroyed already or if it still contains threads.

enumerate

Added in API level 1
int enumerate (Thread[] threads)

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.

Note that this method will silently ignore any threads that don't fit in the supplied array.

Parameters
threads Thread: the array into which the Threads will be copied
Returns
int the number of Threads that were copied

enumerate

Added in API level 1
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. Returns when the array is full or no more groups remain, whichever happens first.

Note that this method will silently ignore any thread groups that don't fit in the supplied array.

Parameters
groups ThreadGroup: the array into which the ThreadGroups will be copied
recurse boolean: indicates whether ThreadGroups in subgroups should be recursively copied as well or not
Returns
int the number of ThreadGroups that were copied

enumerate

Added in API level 1
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. Returns when the array is full or no more threads remain, whichever happens first.

Note that this method will silently ignore any threads that don't fit in the supplied array.

Parameters
threads Thread: the array into which the Threads will be copied
recurse boolean: indicates whether Threads in subgroups should be recursively copied as well
Returns
int the number of Threads that were copied

enumerate

Added in API level 1
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. Returns when the array is full or no more groups remain, whichever happens first.

Note that this method will silently ignore any thread groups that don't fit in the supplied array.

Parameters
groups ThreadGroup: the array into which the ThreadGroups will be copied
Returns
int the number of ThreadGroups that were copied

getMaxPriority

Added in API level 1
int getMaxPriority ()

Returns the maximum allowed priority for a Thread in this thread group.

Returns
int the maximum priority

See also:

getName

Added in API level 1
String getName ()

Returns the name of this thread group.

Returns
String the group's name

getParent

Added in API level 1
ThreadGroup getParent ()

Returns this thread group's parent ThreadGroup. It can be null if this is the the root ThreadGroup.

Returns
ThreadGroup the parent

interrupt

Added in API level 1
void interrupt ()

Interrupts every Thread in this group and recursively in all its subgroups.

See also:

isDaemon

Added in API level 1
boolean isDaemon ()

Checks whether this thread group is a daemon ThreadGroup.

Returns
boolean true if this thread group is a daemon ThreadGroup

See also:

isDestroyed

Added in API level 1
boolean isDestroyed ()

Checks whether this thread group has already been destroyed.

Returns
boolean true if this thread group has already been destroyed

See also:

list

Added in API level 1
void list ()

Outputs to 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.

parentOf

Added in API level 1
boolean parentOf (ThreadGroup g)

Checks whether this thread group is a direct or indirect parent group of a given ThreadGroup.

Parameters
g ThreadGroup: the potential child ThreadGroup
Returns
boolean true if this thread group is parent of g

resume

Added in API level 1
void resume ()

This method was deprecated in API level 1.
Requires deprecated method Thread.resume().

Resumes every thread in this group and recursively in all its subgroups.

See also:

setDaemon

Added in API level 1
void setDaemon (boolean isDaemon)

Sets whether this is a daemon ThreadGroup or not. Daemon thread groups are automatically destroyed when they become empty.

Parameters
isDaemon boolean: the new value

See also:

setMaxPriority

Added in API level 1
void setMaxPriority (int newMax)

Configures the maximum allowed priority for a 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.

Parameters
newMax int: the new maximum priority to be set
Throws
IllegalArgumentException if the new priority is greater than Thread.MAX_PRIORITY or less than Thread.MIN_PRIORITY

See also:

stop

Added in API level 1
void stop ()

This method was deprecated in API level 1.
Requires deprecated method Thread.stop().

Stops every thread in this group and recursively in all its subgroups.

See also:

suspend

Added in API level 1
void suspend ()

This method was deprecated in API level 1.
Requires deprecated method Thread.suspend().

Suspends every thread in this group and recursively in all its subgroups.

See also:

toString

Added in API level 1
String toString ()

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
String a printable representation of this object.

uncaughtException

Added in API level 1
void uncaughtException (Thread t, 
                Throwable e)

Handles uncaught exceptions. Any uncaught exception in any Thread is forwarded to the thread's ThreadGroup by invoking this method.

New code should use setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler) instead of thread groups.

Parameters
t Thread: the Thread that terminated with an uncaught exception
e Throwable: the uncaught exception itself
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.