ThreadGroupEx

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. <p> 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 or any other thread groups.

@author unascribed

Constructors

this
this(string name)

Constructs a new thread group. The parent of this new group is the thread group of the currently running thread. <p> The {@code checkAccess} method of the parent thread group is called with no arguments; this may result in a security exception.

this
this(ThreadGroupEx parent, string name)

Creates a new thread group. The parent of this new group is the specified thread group. <p> The {@code checkAccess} method of the parent thread group is called with no arguments; this may result in a security exception.

Members

Functions

activeCount
int activeCount()

Returns an estimate of the number of active threads in this thread group and its subgroups. Recursively iterates over all subgroups in this thread group.

activeGroupCount
int activeGroupCount()

Returns an estimate of the number of active groups in this thread group and its subgroups. Recursively iterates over all subgroups in this thread group.

add
void add(Thread t)

Adds the specified thread to this thread group.

addUnstarted
void addUnstarted()

Increments the count of unstarted threads in the thread group. Unstarted threads are not added to the thread group so that they can be collected if they are never started, but they must be counted so that daemon thread groups with unstarted threads in them are not destroyed.

checkAccess
void checkAccess()

Determines if the currently running thread has permission to modify this thread group. <p> If there is a security manager, its {@code checkAccess} method is called with this thread group as its argument. This may result in throwing a {@code SecurityException}.

destroy
void destroy()

Destroys this thread group and all of its subgroups. This thread group must be empty, indicating that all threads that had been in this thread group have since stopped. <p> First, the {@code checkAccess} method of this thread group is called with no arguments; this may result in a security exception.

enumerate
int enumerate(Thread[] list)

Copies into the specified array every active thread in this thread group and its subgroups.

enumerate
int enumerate(Thread[] list, bool recurse)

Copies into the specified array every active thread in this thread group. If {@code recurse} is {@code true}, this method recursively enumerates all subgroups of this thread group and references to every active thread in these subgroups are also included. If the array is too short to hold all the threads, the extra threads are silently ignored.

enumerate
int enumerate(ThreadGroupEx[] list)

Copies into the specified array references to every active subgroup in this thread group and its subgroups.

enumerate
int enumerate(ThreadGroupEx[] list, bool recurse)

Copies into the specified array references to every active subgroup in this thread group. If {@code recurse} is {@code true}, this method recursively enumerates all subgroups of this thread group and references to every active thread group in these subgroups are also included.

getMaxPriority
int getMaxPriority()

Returns the maximum priority of this thread group. Threads that are part of this group cannot have a higher priority than the maximum priority.

getName
string getName()

Returns the name of this thread group.

getParent
ThreadGroupEx getParent()

Returns the parent of this thread group. <p> First, if the parent is not {@code null}, the {@code checkAccess} method of the parent thread group is called with no arguments; this may result in a security exception.

interrupt
void interrupt()

Interrupts all threads in this thread group. <p> First, the {@code checkAccess} method of this thread group is called with no arguments; this may result in a security exception. <p> This method then calls the {@code interrupt} method on all the threads in this thread group and in all of its subgroups.

isDaemon
bool isDaemon()

Tests if this thread group is a daemon thread group. A daemon thread group is automatically destroyed when its last thread is stopped or its last thread group is destroyed.

isDestroyed
bool isDestroyed()

Tests if this thread group has been destroyed.

list
void list()

Prints information about this thread group to the standard output. This method is useful only for debugging.

parentOf
bool parentOf(ThreadGroupEx g)

Tests if this thread group is either the thread group argument or one of its ancestor thread groups.

setDaemon
void setDaemon(bool daemon)

Changes the daemon status of this thread group. <p> First, the {@code checkAccess} method of this thread group is called with no arguments; this may result in a security exception. <p> A daemon thread group is automatically destroyed when its last thread is stopped or its last thread group is destroyed.

setMaxPriority
void setMaxPriority(int pri)

Sets the maximum priority of the group. Threads in the thread group that already have a higher priority are not affected. <p> First, the {@code checkAccess} method of this thread group is called with no arguments; this may result in a security exception. <p> If the {@code pri} argument is less than {@link Thread#PRIORITY_MIN} or greater than {@link Thread#PRIORITY_MAX}, the maximum priority of the group remains unchanged. <p> Otherwise, the priority of this ThreadGroupEx object is set to the smaller of the specified {@code pri} and the maximum permitted priority of the parent of this thread group. (If this thread group is the system thread group, which has no parent, then its maximum priority is simply set to {@code pri}.) Then this method is called recursively, with {@code pri} as its argument, for every thread group that belongs to this thread group.

threadStartFailed
void threadStartFailed(Thread t)

Notifies the group that the thread {@code t} has failed an attempt to start.

threadTerminated
void threadTerminated(Thread t)

Notifies the group that the thread {@code t} has terminated.

uncaughtException
void uncaughtException(Thread t, Throwable e)

Called by the Java Virtual Machine when a thread in this thread group stops because of an uncaught exception, and the thread does not have a specific {@link Thread.UncaughtExceptionHandler} installed. <p> The {@code uncaughtException} method of {@code ThreadGroupEx} does the following: <ul> <li>If this thread group has a parent thread group, the {@code uncaughtException} method of that parent is called with the same two arguments. <li>Otherwise, this method checks to see if there is a {@linkplain Thread#getDefaultUncaughtExceptionHandler default uncaught exception handler} installed, and if so, its {@code uncaughtException} method is called with the same two arguments. <li>Otherwise, this method determines if the {@code Throwable} argument is an instance of {@link ThreadDeath}. If so, nothing special is done. Otherwise, a message containing the thread's name, as returned from the thread's {@link Thread#getName getName} method, and a stack backtrace, using the {@code Throwable}'s {@link Throwable#printStackTrace printStackTrace} method, is printed to the {@linkplain System#err standard error stream}. </ul> <p> Applications can override this method in subclasses of {@code ThreadGroupEx} to provide alternative handling of uncaught exceptions.

Variables

daemon
bool daemon;
Undocumented in source.
destroyed
bool destroyed;
Undocumented in source.
groups
ThreadGroupEx[] groups;
Undocumented in source.
maxPriority
int maxPriority;
Undocumented in source.
nUnstartedThreads
int nUnstartedThreads;
Undocumented in source.
name
string name;
Undocumented in source.
ngroups
int ngroups;
Undocumented in source.
nthreads
int nthreads;
Undocumented in source.
threads
Thread[] threads;
Undocumented in source.

Inherited Members

From UncaughtExceptionHandler

uncaughtException
void uncaughtException(Thread t, Throwable e)

Method invoked when the given thread terminates due to the given uncaught exception. <p>Any exception thrown by this method will be ignored by the Java Virtual Machine. @param t the thread @param e the exception

Meta