Multithreading Interview Questions
37. Explain Thread Group. Why should we not use it?
ThreadGroup is a class that is used to create multiple groups of threads in a single
object. This group of threads is present in the form of three structures in which every
thread group has a parent except the initial thread. Thread groups can contain other
thread groups also. A thread is only allowed to have access to information about its
own thread group, not other thread groups.
Previously in the old version of Java, the only functionality that did not work without
a thread group was uncaughtException( Thread t, Throwable e). But now in Java 5
versions, there is
Thread.setUncaughtExceptionHandler(UncaughtExceptionHandler). So now even
that works without thread groups and therefore, there is no need to use thread
groups.
t1.setUncaughtExceptionHandler(
new UncaughtExceptionHandler()
{
@Override
Do'stlaringiz bilan baham: