An interesting functionality offered by the concurrency API of Java is the ability to group the threads. This allows us to treat the threads of a group as a single unit and provides access to the
Thread objects that belong to a group to do an operation with them. For example, you have some threads doing the same task and you want to control them, irrespective of how many threads are still running, the status of each one will interrupt all of them with a single call.
Java provides the
ThreadGroup class to work with groups of threads. A
ThreadGroup object can be formed by
Thread objects and by another
ThreadGroup object, generating a tree structure of threads.
In this recipe, we will learn to work with
ThreadGroup objects ...