ThreadGroup Class - Collection Management Methods


The ThreadGroup provides a set of methods that manage the threads and subgroups within the group and allow other objects to query the ThreadGroup for information about its contents. For example, you can call ThreadGroup's activeCount method to find out the number of active threads currently in the group. The activeCount method is often used with the enumerate method to get an array filled with references to all the active threads in a ThreadGroup. For example, the listCurrentThreads method in the following example fills an array with all of the active threads in the current thread group and prints their names:

class EnumerateTest {
void listCurrentThreads() {
ThreadGroup currentGroup = Thread.currentThread().getThreadGroup();
int numThreads;
Thread[] listOfThreads;


numThreads = currentGroup.activeCount();
listOfThreads = new Thread[numThreads];
currentGroup.enumerate(listOfThreads);
for (int i = 0; i < numThreads; i++) {
System.out.println("Thread #" + i + " = " + listOfThreads[i].getName());
}
}
}
Other collection management methods provided by the ThreadGroup class include activeGroupCount and list.

Related Posts:-

People who read this post also read :



1 comments:

If you're trying hard to lose fat then you have to get on this totally brand new tailor-made keto meal plan diet.

To create this keto diet service, certified nutritionists, personal trainers, and professional chefs united to produce keto meal plans that are productive, convenient, money-efficient, and delightful.

From their launch in early 2019, 1000's of clients have already transformed their figure and well-being with the benefits a smart keto meal plan diet can provide.

Speaking of benefits; clicking this link, you'll discover eight scientifically-proven ones provided by the keto meal plan diet.

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More