Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the benefit of ThreadGroup in java over creating separate threads?

Tags:

Many methods like stop(), resume(), suspend() etc are deprecated.

So is it useful to create threads using ThreadGroup?

like image 711
sacsha Avatar asked Oct 30 '09 10:10

sacsha


People also ask

What is the use of ThreadGroup in Java?

ThreadGroup creates a group of threads. 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. The thread group form a tree in which every thread group except the initial thread group has a parent.

What is a ThreadGroup?

Thread groups provide a mechanism for collecting multiple threads into a single object and manipulating those threads all at once, rather than individually. For example, you can start or suspend all the threads within a group with a single method call.

What is the advantage of thread pool in Java?

Advantages of a Thread PoolBetter performance. Saves time. No need to create a thread again and again. Easy to access.

What is the difference between thread pool and thread group?

Thread group class was created in JDK 1.0 to manage the state of multiple threads at once e.g suspend, resume etc. Later most of its important methods were deprecated because of potential deadlock they can create. Thread pool is an architectural concept where multiple threads form a worker pool that works together.


1 Answers

Using ThreadGroup can be a useful diagnostic technique in big application servers with thousands of threads. If your threads are logically grouped together, then when you get a stack trace you can see which group the offending thread was part of (e.g. "Tomcat threads", "MDB threads", "thread pool X", etc), which can be a big help in tracking down and fixing the problem.

like image 191
skaffman Avatar answered Sep 21 '22 13:09

skaffman