Packages  This Package  Prev  Next  Index  

§1.20 Class ThreadGroup

public  class  java.lang.ThreadGroup
    extends  java.lang.Object  (I-§1.12)
{
        // Constructors
    public ThreadGroup(String  name);	§1.20.1
    public ThreadGroup(ThreadGroup  parent, String  name);  §1.20.2
  
        // Methods
    public int activeCount();	§1.20.3
    public int activeGroupCount();	§1.20.4
    public final void checkAccess();	§1.20.5
    public final void destroy();	§1.20.6
    public int enumerate(Thread  list[]);	§1.20.7
    public int enumerate(Thread  list[], boolean  recurse);	§1.20.8
    public int enumerate(ThreadGroup  list[]);	§1.20.9
    public int enumerate(ThreadGroup  list[], boolean  recurse); §1.20.10
    public final int getMaxPriority();	§1.20.11
    public final String getName();	§1.20.12
    public final ThreadGroup getParent();	§1.20.13
    public final boolean isDaemon();	§1.20.14
    public void list();	§1.20.15
    public final boolean parentOf(ThreadGroup  g);	§1.20.16
    public final void resume();	§1.20.17
    public final void setDaemon(boolean  daemon);	§1.20.18
    public final void  setMaxPriority(int  pri);	§1.20.19
    public final void stop();	§1.20.20
    public final void suspend();	§1.20.21
    public String toString();	§1.20.22
    public void uncaughtException(Thread  t, Throwable  e);  §1.20.23
}
A thread group represents a set of threads. In addition, a thread group can also include other thread groups. The thread groups form a tree in which every thread group except the initial thread group has a parent.

A thread is allowed to access information about its own thread group, but not to access information about its thread group's parent thread group.


Constructors

ThreadGroup

public ThreadGroup(String name)
Constructs a new thread group, whose parent is the thread group of the currently running thread.
Parameters:
name - the name of the new thread group

ThreadGroup

public ThreadGroup(ThreadGroup parent, String name)
Creates a new thread group whose parent is the specified thread group.
The checkAccess method (I-§1.20.5) of the parent thread group is called with no arguments; this may result in a security exception(I-§1.43).

Parameters:
parent - the parent thread group
name - the name of the new thread group
Throws
NullPointerException (I-§1.40)
If the thread group argument is null.
Throws
SecurityException (I-§1.43)
If the current thread cannot create a thread in the specified thread group.

Methods

activeCount

public int activeCount()
Returns:
The number of active threads in this thread group and in any other thread group that has this thread group as an ancestor.

activeGroupCount

public int activeGroupCount()
Returns:
The number of active thread groups with this thread group as an ancestor.

checkAccess

public final void checkAccess()
Determines if the currently running thread has permission to modify this thread group.
If there is a security manager, its checkAccess method (I-§1.15.5) is called with this thread group as its argument. This may result in throwing a SecurityException.

Throws
SecurityException (I-§1.43)
If the current thread is not allowed to access this thread group.

destroy

public final void destroy()
Destroys this thread group and all of its sub-groups. This thread group must be empty, indicating that all threads that had been in this thread group have since stopped.
Throws
IllegalThreadStateException (I-§1.34)
If the thread group is not empty or if the thread group has already destroyed.
Throws
SecurityException (I-§1.43)
If the current thread cannot modify this thread group.

enumerate

public int enumerate(Thread list[])
Copies into the specified array every active thread in this thread group and its sub-groups.
An application should use the activeCount method (I-§1.20.3) to get an estimate of how big the array should be. If the array is too short to hold all the threads, the extra threads are silently ignored.

Parameters:
list - an array into which to place the list of threads
Returns:
the number of threads put into the array

enumerate

public int enumerate(Thread list[], boolean recurse)
Copies into the specified array every active thread in this thread group. If the recurse flag is true references to every active thread in this thread's sub- groups are also included. If the array is too short to hold all the threads, the extra threads are silently ignored.
An application should use the activeCount method (I-§1.20.3) to get an estimate of how big the array should be.

Parameters:
list - an array into which to place the list of threads
recurse - flag indicating whether to also include threads in sub-thread groups.
Returns:
the number of threads placed into the array.

enumerate

public int enumerate(ThreadGroup list[])
Copies into the specified array references to every active sub-group in this thread group.
An application should use the activeGroupCount method (I-§1.20.4) to get an estimate of how big the array should be. If the array is too short to hold all the thread groups, the extra thread groups are silently ignored.

Parameters:
list - an array into which to place the list of thread groups
Returns:
the number of thread groups put into the array

enumerate

public int enumerate(ThreadGroup list[], boolean recurse)
Copies into the specified array references to every active sub-group in this thread group. If the recurse flag is true references to every active, all sub- thread groups of the sub-thread groups and so forth are also included.
An application should use the activeGroupCount method (I-§1.20.4) to get an estimate of how big the array should be.

Parameters:
list - an array into which to place the list of threads
recurse - flag indicating whether to recursively enumerate all included thread groups.
Returns:
the number of thread groups put into the array.

getMaxPriority

public final int getMaxPriority()
Returns:
the maximum priority that a thread in this thread group can have.

getName

public final String getName()
Returns:
the name of this thread group.

getParent

public final ThreadGroup getParent()
Returns:
the parent of this thread group. The top-level thread group is the only thread group whose parent is null.

isDaemon

public final boolean isDaemon()
Determines if this thread group is a dæmon thread group. A dæmon thread group is automatically destroyed when its last thread is stopped or its last thread group is destroyed.
Returns:
true if this thread group is a dæmon thread group; false otherwise.

list

public void list()
Prints information about this thread group to the standard output. This method is useful only for debugging.

parentOf

public final boolean parentOf(ThreadGroup g)
Determines if this thread group is either the thread group argument or one of its ancestor thread groups.
Parameters:
g - a thread group
Returns:
true if this thread group is the thread group argument or one of its ancestor thread groups; false otherwise.

resume

public final void resume()
Resumes all processes in this thread group.
First, the checkAccess method (I-§1.20.5) of this thread group is called with no arguments; this may result in a security exception(I-§1.43).


This method then calls the resume method (I-§1.19.29) on all the threads in this thread group and in all of its sub-thread groups.

Throws
SecurityException (I-§1.43)
If the current thread is not allowed to access this thread group or any of the threads in the thread group.

setDaemon

public final void setDaemon(boolean daemon)
Sets whether this thread group is a dæmon thread group.
First, the checkAccess method (I-§1.20.5) of this thread group is called with no arguments; this may result in a security exception(I-§1.43).


Marks whether this thread is a dæmon thread group. A dæmon thread group is automatically destroyed when its last thread is stopped or its last thread group is destroyed.
Parameters:
daemon - if true, marks this thread group as a dæmon thread group; otherwise, marks this thread group as normal.
Throws
SecurityException (I-§1.43)
If the current thread cannot modify this thread.

setMaxPriority

public final void setMaxPriority(int pri)
Sets the maximum priority of the group.
First, the checkAccess method (I-§1.20.5) of this thread group is called with no arguments; this may result in a security exception (I-§1.43).


Threads in the thread group that already have a higher priority are not affected.
Parameters:
pri - the new priority of the Thread group
Throws
SecurityException (I-§1.43)
If the current thread cannot modify this thread group.

stop

public final void stop()
Stops all processes in this thread group.
First, the checkAccess method (I-§1.20.5) of this thread group is called with no arguments; this may result in a security exception(I-§1.43).


This method then calls the stop method (I-§1.19.37) on all the threads in this thread group and in all of its sub-thread groups.

Throws
SecurityException (I-§1.43)
If the current thread is not allowed to access this thread group or any of the threads in the thread group.

suspend

public final void suspend()
Suspends all processes in this thread group.
First, the checkAccess method (I-§1.20.5) of this thread group is called with no arguments; this may result in a security exception(I-§1.43).


This method then calls the suspend method (I-§1.19.39) on all the threads in this thread group and in all of its sub-thread groups.

Throws
SecurityException (I-§1.43)
If the current thread is not allowed to access this thread group or any of the threads in the thread group.

toString

public String toString()
Returns:
a string representation of this thread group.
Overrides:
toString in class Object (I-§1.12.9).

uncaughtException

public void uncaughtException(Thread t, Throwable e)
The Java Virtual Machine calls this method when a thread in this thread group stops because of an uncaught exception.
The uncaughtException method of ThreadGroup does the following:
  1. If this thread group has a parent thread group, the uncaughtException method of that parent is called with the same two arguments.
  1. Otherwise, this method determines if the Throwable argument is an instance of ThreadDeath (I-§1.59). If so, nothing special is done.. Otherwise, the Throwable's printStackTrace method (I-§1.21.6) is called to print a stack back trace to the standard error stream (I-§1.18.1).
Applications can override this method in subclasses of ThreadGroup to provide alternative handling of uncaught exceptions.
Parameters:
t - the thread that is about to exit
e - the uncaught exception

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com