ThreadGroup in Java

Java provides a convenient way to group multiple threads in a single object. In such way, we can suspend, resume or interrupt group of threads by a single method call.

Note: Now suspend(), resume() and stop() methods are deprecated.

Constructors of ThreadGroup clas

There are only two constructors of ThreadGroup class.

SNo Method Description
1 ThreadGroup(String name) creates a thread group with given name.
2 ThreadGroup(ThreadGroup parent, String name) creates a thread group with given parent group and name.

Important methods of ThreadGroup class

There are many methods in ThreadGroup class. A list of important methods are given below.

SNo Method Description
1 int activeCount() returns no. of threads running in current group.
2 int activeGroupCount() returns a no. of active group in this thread group.
3 void destroy() destroys this thread group and all its sub groups.
4 String getName() returns the name of this group.
5 ThreadGroup getParent() returns the parent of this group.
6 void interrupt() interrupts all threads of this group.
7 void list() prints information of this group to standard console.

ThreadGroup Example

Flash Soon

Copyright 2017 Design& Development