Java Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 6.00

"ThreadGroup" Class - Container of Threads and Thread Groups

This section describes the 'ThreadGroup' class and its main methods. A 'ThreadGroup' object is a container of threads and thread groups.

ThreadGroup: A class represents a collection of Thread objects and ThreadGroup objects.

Features of the ThreadGroup class:

  • All objects of ThreadGroup class are organized as a tree structure. Each ThreadGroup object must have a parent ThreadGroup object in the tree, except the root object.
  • The root object of the ThreadGroup tree is provided and managed by the Java Virtual Machine (JVM).

Main methods:

  • getParent(): Returns the parent ThreadGroup object.
  • activeCount(): Returns the number of active Thread objects in this ThreadGroup object and its sub-tree.
  • activeGroupCount(): Returns the number of active ThreadGroup objects in this ThreadGroup object and its sub-tree.
  • enumerate(Thread[] l): Copies active Thread objects in this ThreadGroup object and its sub-tree.
  • enumerate(ThreadGroup[] l): Copies active ThreadGroup objects in this ThreadGroup object and its sub-tree.
  • interrupt(): Calls Thread.interrupt() method on all Thread objects in this ThreadGroup object and its sub-tree.

Sections in This Chapter

"ThreadGroup" Class - Container of Threads and Thread Groups

Displaying the "system" ThreadGroup Tree

Adding Threads and Thread Groups

JDK 1.3 Bug - Memory Leak With Unstarted Threads

Dr. Herong Yang, updated in 2008
"ThreadGroup" Class - Container of Threads and Thread Groups