ThreadGroup in Java

A ThreadGroup represents a set of threads. A thread group can also include the other thread group.

It offers a convenient way to manage groups of threads as a unit. This is particularly valuable in situation in which you want to suspend and resume a number of related threads.

Some of the important methods defined in ThreadGroup

activeCount() : provides the number of active threads in the thread group and its subgroups.

activeGroupCount() : provides the number of active groups in the thread group and its subgroups.

destroy() : destroys the thread group and all of its subgroups.

interrupt() : interrupts all threads in the thread group.

suspend() : suspends all threads in the thread group.

stop() : stops all threads in the thread group.

Screen Shot 2020-02-06 at 7.28.45 PM

Output

Screen Shot 2020-02-06 at 7.28.53 PM

 

Leave a Reply

Your email address will not be published. Required fields are marked *