Name

ThreadGroup

Synopsis

This class represents a group of threads and allows that group to be manipulated as a whole. A ThreadGroup can contain Thread objects, as well as other child ThreadGroup objects. All ThreadGroup objects are created as children of some other ThreadGroup, and thus there is a parent/child hierarchy of ThreadGroup objects. Use getParent( ) to obtain the parent ThreadGroup, and use activeCount( ) , activeGroupCount( ), and the various enumerate( ) methods to list the child Thread and ThreadGroup objects. Most applications can simply rely on the default system thread group. System-level code and applications such as servers that need to create a large number of threads may find it convenient to create their own ThreadGroup objects, however.

interrupt( ) interrupts all threads in the group at once. setMaxPriority( ) specifies the maximum priority any thread in the group can have. checkAccess( ) checks whether the calling thread has permission to modify the given thread group. The method throws a SecurityException if the current thread does not have access. uncaughtException( ) contains the code that is run when a thread terminates because of an uncaught exception or error. You can customize this method by subclassing ThreadGroup.

java.lang.ThreadGroup

Figure 10-65. java.lang.ThreadGroup

public class ThreadGroup implements Thread.UncaughtExceptionHandler {
// Public Constructors ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.