Android APIs
public class

ThreadGroup

extends Object
implements Thread.UncaughtExceptionHandler
java.lang.Object
   ↳ java.lang.ThreadGroup

Class Overview

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.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Thread.UncaughtExceptionHandler

Public Constructors

public ThreadGroup (String name)

Added in API level 1

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 the name
See Also

public ThreadGroup (ThreadGroup parent, String name)

Added in API level 1

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

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

Public Methods

public int activeCount ()

Added in API level 1

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

Returns
  • the number of children

public int activeGroupCount ()

Added in API level 1

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

Returns
  • the number of children

public boolean allowThreadSuspension (boolean b)

Added in API level 1

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 Used to control low memory implicit suspension
Returns
  • true (always)

public final void checkAccess ()

Added in API level 1

Does nothing.

public final void destroy ()

Added in API level 1

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.

public int enumerate (Thread[] threads)

Added in API level 1

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 the array into which the Threads will be copied
Returns
  • the number of Threads that were copied

public int enumerate (ThreadGroup[] groups, boolean recurse)

Added in API level 1

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 the array into which the ThreadGroups will be copied
recurse indicates whether ThreadGroups in subgroups should be recursively copied as well or not
Returns
  • the number of ThreadGroups that were copied

public int enumerate (Thread[] threads, boolean recurse)

Added in API level 1

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 the array into which the Threads will be copied
recurse indicates whether Threads in subgroups should be recursively copied as well
Returns
  • the number of Threads that were copied

public int enumerate (ThreadGroup[] groups)

Added in API level 1

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 the array into which the ThreadGroups will be copied
Returns
  • the number of ThreadGroups that were copied

public final int getMaxPriority ()

Added in API level 1

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

Returns
  • the maximum priority

public final String getName ()

Added in API level 1

Returns the name of this thread group.

Returns
  • the group's name

public final ThreadGroup getParent ()

Added in API level 1

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

Returns
  • the parent

public final void interrupt ()

Added in API level 1

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

See Also

public final boolean isDaemon ()

Added in API level 1

Checks whether this thread group is a daemon ThreadGroup.

Returns
  • true if this thread group is a daemon ThreadGroup

public boolean isDestroyed ()

Added in API level 1

Checks whether this thread group has already been destroyed.

Returns
  • true if this thread group has already been destroyed
See Also

public void list ()

Added in API level 1

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.

public final boolean parentOf (ThreadGroup g)

Added in API level 1

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

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

public final void resume ()

Added in API level 1

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.

public final void setDaemon (boolean isDaemon)

Added in API level 1

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

Parameters
isDaemon the new value

public final void setMaxPriority (int newMax)

Added in API level 1

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 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

public final void stop ()

Added in API level 1

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.

public final void suspend ()

Added in API level 1

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.

public String toString ()

Added in API level 1

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
  • a printable representation of this object.

public void uncaughtException (Thread t, Throwable e)

Added in API level 1

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 the Thread that terminated with an uncaught exception
e the uncaught exception itself