You can destroy a thread group by using destroy()
method of ThreadGroup
class. It will cleans up the thread group and removes it from the thread group hierarchy. It’s not only destroy the thread group, but also all its subgroups.
The destroy()
method is of limited use: it can only be called if there are no threads presently in the thread group.
package org.kodejava.lang;
public class ThreadGroupDestroy {
public static void main(String[] args) {
ThreadGroup root = new ThreadGroup("Root");
ThreadGroup server = new ThreadGroup(root, "ServerGroup");
ThreadGroup client = new ThreadGroup(root, "ClientGroup");
// Destroy 'root' thread groups and all its subgroup
// ('server' & 'client')
root.destroy();
// Check if 'root' group and its subgroups already destroyed
if (root.isDestroyed()) {
System.out.println("Root group is destroyed");
}
if (server.isDestroyed()) {
System.out.println("Server group is destroyed");
}
if (client.isDestroyed()) {
System.out.println("Client group is destroyed");
}
}
}
Latest posts by Wayan (see all)
- How do I create a string of repeated characters? - September 1, 2023
- How do I convert datetime string with optional part to a date object? - August 28, 2023
- How do I split large excel file into multiple smaller files? - April 15, 2023