Android
java.lang
public class

java.lang.ThreadGroup

java.lang.Object
java.lang.ThreadGroup Thread.UncaughtExceptionHandler

An implementation of this class is provided, but the documented constructors are used by the vm specific implementation to create the required "system" and "main" ThreadGroups. The documented methods are used by java.lang.Thread to add and remove Threads from their ThreadGroups. 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.

Summary

Public Constructors

            ThreadGroup(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 ThreadGroup parent

Public Methods

          int  activeCount()
Returns the number of Threads which are children of the receiver, directly or indirectly.
          int  activeGroupCount()
Returns the number of ThreadGroups which are children of the receiver, directly or indirectly.
          boolean  allowThreadSuspension(boolean b)
This method is deprecated. Required deprecated method suspend().
    final      void  checkAccess()
If there is a SecurityManager installed, call checkAccess in it passing the receiver as parameter, otherwise do nothing.
    final      void  destroy()
Destroys the receiver and recursively all its subgroups.
          int  enumerate(ThreadGroup[] groups)
Copies an array with all ThreadGroups which are children of the receiver (directly or indirectly) into the array groups passed as parameters.
          int  enumerate(ThreadGroup[] groups, boolean recurse)
Copies an array with all ThreadGroups which are children of the receiver into the array groups passed as parameter.
          int  enumerate(Thread[] threads, boolean recurse)
Copies an array with all Threads which are children of the receiver into the array threads passed as parameter.
          int  enumerate(Thread[] threads)
Copies an array with all Threads which are children of the receiver (directly or indirectly) into the array threads passed as parameters.
    final      int  getMaxPriority()
Returns the maximum allowed priority for a Thread in the receiver.
    final      String  getName()
Returns the name of the receiver.
    final      ThreadGroup  getParent()
Returns the receiver's parent ThreadGroup.
    final      void  interrupt()
Interrupts every Thread in the receiver and recursively in all its subgroups.
    final      boolean  isDaemon()
Returns true if the receiver is a daemon ThreadGroup, false otherwise.
  synchronized        boolean  isDestroyed()
Returns true if the receiver has been destroyed already, false otherwise.
          void  list()
Outputs to System.out a text representation of the hierarchy of Threads and ThreadGroups in the receiver (and recursively).
    final      boolean  parentOf(ThreadGroup g)
Returns true if the receiver is a direct or indirect parent group of ThreadGroup g, false otherwise.
    final      void  resume()
This method is deprecated. Requires deprecated method Thread.resume().
    final      void  setDaemon(boolean isDaemon)
Configures the receiver to be a daemon ThreadGroup or not.
    final      void  setMaxPriority(int newMax)
Configures the maximum allowed priority for a Thread in the receiver and recursively in all its subgroups.
    final      void  stop()
This method is deprecated. Requires deprecated method Thread.stop().
    final      void  suspend()
This method is deprecated. Requires deprecated method Thread.suspend().
          String  toString()
Returns a string containing a concise, human-readable description of the receiver.
          void  uncaughtException(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).
Methods inherited from class java.lang.Object
Methods inherited from interface java.lang.Thread.UncaughtExceptionHandler

Details

Public Constructors

public ThreadGroup(String name)

Constructs a new ThreadGroup with the name provided. The new ThreadGroup will be child of the ThreadGroup to which the Thread.currentThread() belongs.

Parameters

name Name for the ThreadGroup being created

Throws

SecurityException if checkAccess() for the parent group fails with a SecurityException

See Also

public ThreadGroup(ThreadGroup parent, String name)

Constructs a new ThreadGroup with the name provided, as child of the ThreadGroup parent

Parameters

parent Parent ThreadGroup
name Name for the ThreadGroup being created

Throws

NullPointerException if parent is null
SecurityException if checkAccess() for the parent group fails with a SecurityException
IllegalThreadStateException if parent has been destroyed already

Public Methods

public int activeCount()

Returns the number of Threads which are children of the receiver, directly or indirectly.

Returns

  • Number of children Threads

public int activeGroupCount()

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

Returns

  • Number of children ThreadGroups

public boolean allowThreadSuspension(boolean b)

This method is deprecated. Required deprecated method suspend().

The definition of this method depends on the deprecated method suspend(). The behavior of this call was never specified.

Parameters

b Used to control low memory implicit suspension

public final void checkAccess()

If there is a SecurityManager installed, call checkAccess in it passing the receiver as parameter, otherwise do nothing.

public final void destroy()

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 already
SecurityException if this.checkAccess() fails with a SecurityException

public int enumerate(ThreadGroup[] groups)

Copies an array with all ThreadGroups which are children of the receiver (directly or indirectly) into the array groups passed 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

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

Copies an array with all ThreadGroups which are children of the receiver into the array groups passed as parameter. Children ThreadGroups of subgroups are recursively copied as well if parameter recurse is true. 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
recurse Indicates whether ThreadGroups in subgroups should be recursively copied as well or not

Returns

  • How many ThreadGroups were copied over

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

Copies an array with all Threads which are children of the receiver into the array threads passed as parameter. Children Threads of subgroups are recursively copied as well if parameter recurse is true. 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 copied
recurse Indicates whether Threads in subgroups should be recursively copied as well or not

Returns

  • How many Threads were copied over

public int enumerate(Thread[] threads)

Copies an array with all Threads which are children of the receiver (directly or indirectly) into the array threads passed 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

public final int getMaxPriority()

Returns the maximum allowed priority for a Thread in the receiver.

Returns

  • the maximum priority (an int)

public final String getName()

Returns the name of the receiver.

Returns

  • the receiver's name (a java.lang.String)

public final ThreadGroup getParent()

Returns the receiver's parent ThreadGroup. It can be null if the receiver is the the root ThreadGroup.

Returns

  • the parent ThreadGroup

public final void interrupt()

Interrupts every Thread in the receiver and recursively in all its subgroups.

Throws

SecurityException if this.checkAccess() fails with a SecurityException

See Also

public final boolean isDaemon()

Returns true if the receiver is a daemon ThreadGroup, false otherwise.

Returns

  • if the receiver is a daemon ThreadGroup

public synchronized boolean isDestroyed()

Returns true if the receiver has been destroyed already, false otherwise.

Returns

  • if the receiver has been destroyed already

See Also

public void list()

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.

public final boolean parentOf(ThreadGroup g)

Returns true if the receiver is a direct or indirect parent group of ThreadGroup g, false otherwise.

Parameters

g ThreadGroup to test

Returns

  • if the receiver is parent of the ThreadGroup passed as parameter

public final void resume()

This method is deprecated. Requires deprecated method Thread.resume().

Resumes every Thread in the receiver and recursively in all its subgroups.

Throws

SecurityException if this.checkAccess() fails with a SecurityException

See Also

public final void setDaemon(boolean isDaemon)

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 if checkAccess() for the parent group fails with a SecurityException

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 if checkAccess() fails with a SecurityException
IllegalArgumentException if the new priority is greater than Thread.MAX_PRIORITY or less than Thread.MIN_PRIORITY

See Also

public final void stop()

This method is deprecated. Requires deprecated method Thread.stop().

Stops every Thread in the receiver and recursively in all its subgroups.

Throws

SecurityException if this.checkAccess() fails with a SecurityException

public final void suspend()

This method is deprecated. Requires deprecated method Thread.suspend().

Suspends every Thread in the receiver and recursively in all its subgroups.

Throws

SecurityException if this.checkAccess() fails with a SecurityException

See Also

public String toString()

Returns a string containing a concise, human-readable description of the receiver.

Returns

  • a printable representation for the receiver.

public void uncaughtException(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). This allows users to define custom ThreadGroup classes and custom behavior for when a Thread has an uncaughtException or when it does (ThreadDeath).

Parameters

t Thread with an uncaught exception
e The uncaught exception itself
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48