Many methods like stop()
, resume()
, suspend()
etc are deprecated.
So is it useful to create threads using ThreadGroup
?
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.
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.
Advantages of a Thread PoolBetter performance. Saves time. No need to create a thread again and again. Easy to access.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With