You can use ThreadGroup.isDestroyed()
method to check whether a thread group and its subgroups has been destroyed.
package org.kodejava.lang;
public class CheckGroupDestroy {
public static void main(String[] args) {
ThreadGroup grandParent = new ThreadGroup("GrandParent");
ThreadGroup uncle = new ThreadGroup(grandParent, "Uncle");
ThreadGroup parent = new ThreadGroup(grandParent, "Parent");
ThreadGroup son = new ThreadGroup(parent, "Son");
ThreadGroup daughter = new ThreadGroup(parent, "Daughter");
ThreadGroup neighbour = new ThreadGroup("Neighbour");
ThreadGroup[] groupArray = {
grandParent, uncle, parent, son, daughter, neighbour
};
// Destroy 'parent' group and all its subgroups
parent.destroy();
// Check whether the group is destroyed. The result is,
// GrandParent, Uncle, and Neighbour did not destroyed
// because they are not Parent's subgroups
for (ThreadGroup tg : groupArray) {
if (tg.isDestroyed()) {
System.out.println(tg.getName() + " is destroyed");
} else {
System.out.println(tg.getName() + " is not destroyed");
}
}
}
}
The result is:
GrandParent is not destroyed
Uncle is not destroyed
Parent is destroyed
Son is destroyed
Daughter is destroyed
Neighbour is not destroyed
Latest posts by Wayan (see all)
- How do I split large excel file into multiple smaller files? - April 15, 2023
- How do I get the number of processors available to the JVM? - March 29, 2023
- How do I show Spring transaction in log / console? - March 29, 2023