Package java.lang |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public class java.lang.ThreadGroup extends java.lang.Object { // Constructors public ThreadGroup(String name); public ThreadGroup(ThreadGroup parent, String name); // Methods public int activeCount(); public int activeGroupCount(); public final void checkAccess(); public final void destroy(); public int enumerate(Thread list[]); public int enumerate(Thread list[], boolean recurse); public int enumerate(ThreadGroup list[]); public int enumerate(ThreadGroup list[], boolean recurse); public final int getMaxPriority(); public final String getName(); public final ThreadGroup getParent(); public final boolean isDaemon(); public void list(); public final boolean parentOf(ThreadGroup g); public final void resume(); public final void setDaemon(boolean daemon); public final void setMaxPriority(int pri); public final void stop(); public final void suspend(); public String toString(); public void uncaughtException(Thread t, Throwable e); }
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.
public ThreadGroup(String name)Constructs a new thread group, whose parent is the thread group of the currently running thread.
Parameter Description name the name of the new thread group
public ThreadGroup(ThreadGroup parent, String name)Creates a new thread group whose parent is the specified thread group.
The checkAccess method of the parent thread group is called with no arguments; this may result in a security exception.
Parameter Description parent the parent thread group name the name of the new thread group Throw:
If the thread group argument is null.
Throw:
If the current thread cannot create a thread in the specified thread group.
public int activeCount()Return Value:
Returns The number of active threads in this thread group and in any other thread group that has this thread group as an ancestor.
public int activeGroupCount()Return Value:
Returns The number of active thread groups with this thread group as an ancestor.
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 is called with this thread group as its argument. This may result in throwing a SecurityException.
Throw:
If the current thread is not allowed to access this thread group.
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.
Throw:
If the thread group is not empty or if the thread group has already destroyed.
Throw:
If the current thread cannot modify this thread group.
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 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.
Return Value:
Returns the number of threads put into the array
Parameter Description list an array into which to place the list of threads
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 to get an estimate of how big the array should be.
Return Value:
Returns the number of threads placed into the array.
Parameter Description list an array into which to place the list of threads recurse flag indicating whether to also include threads in sub-thread groups.
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 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.
Return Value:
Returns the number of thread groups put into the array
Parameter Description list an array into which to place the list of thread groups
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 to get an estimate of how big the array should be.
Return Value:
Returns the number of thread groups put into the array.
Parameter Description list an array into which to place the list of threads recurse flag indicating whether to recursively enumerate all included thread groups.
public final int getMaxPriority()Return Value:
Returns the maximum priority that a thread in this thread group can have.
public final String getName()Return Value:
Returns the name of this thread group.
public final ThreadGroup getParent()Return Value:
Returns the parent of this thread group. The top-level thread group is the only thread group whose parent is null.
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.
Return Value:
Returns true if this thread group is a dæmon thread group; false otherwise.
public void list()Prints information about this thread group to the standard output. This method is useful only for debugging.
public final boolean parentOf(ThreadGroup g)Determines if this thread group is either the thread group argument or one of its ancestor thread groups.
Return Value:
Returns true if this thread group is the thread group argument or one of its ancestor thread groups; false otherwise.
Parameter Description g a thread group
public final void resume()Resumes all processes in this thread group.
First, the checkAccess method of this thread group is called with no arguments; this may result in a security exception.
This method then calls the resume method on all the threads in this thread group and in all of its sub-thread groups.
Throw:
If the current thread is not allowed to access this thread group or any of the threads in the thread group.
public final void setDaemon(boolean daemon)Sets whether this thread group is a dæmon thread group.
First, the checkAccess method of this thread group is called with no arguments; this may result in a security exception.
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.
Parameter Description daemon if true, marks this thread group as a dæmon thread group; otherwise, marks this thread group as normal. Throw:
If the current thread cannot modify this thread.
public final void setMaxPriority(int pri)Sets the maximum priority of the group.
First, the checkAccess method of this thread group is called with no arguments; this may result in a security exception .
Threads in the thread group that already have a higher priority are not affected.
Parameter Description pri the new priority of the Thread group Throw:
If the current thread cannot modify this thread group.
public final void stop()Stops all processes in this thread group.
First, the checkAccess method of this thread group is called with no arguments; this may result in a security exception.
This method then calls the stop method on all the threads in this thread group and in all of its sub-thread groups.
Throw:
If the current thread is not allowed to access this thread group or any of the threads in the thread group.
public final void suspend()Suspends all processes in this thread group.
First, the checkAccess method of this thread group is called with no arguments; this may result in a security exception.
This method then calls the suspend method on all the threads in this thread group and in all of its sub-thread groups.
Throw:
If the current thread is not allowed to access this thread group or any of the threads in the thread group.
public String toString()Return Value:
Returns a string representation of this thread group.
Overrides:
toString in class Object .
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:
- If this thread group has a parent thread group, the uncaughtException method of that parent is called with the same two arguments.
- Otherwise, this method determines if the Throwable argument is an instance of ThreadDeath . If so, nothing special is done.. Otherwise, the Throwable's printStackTrace method is called to print a stack back trace to the standard error stream .
Applications can override this method in subclasses of ThreadGroup to provide alternative handling of uncaught exceptions.
Parameter Description t the thread that is about to exit e the uncaught exception