You are on page 1of 1

Introduction

We know earlier, every thread should belong to some thread group and if no group is
mentioned, the thread is placed, by default, in main thread group. When the JVM starts a
new process, it creates main thread group and every thread created by the programmer, if not
mentioned any group, the JVM keeps the thread in the main thread group. The programmer can
explicitly mention a thread group also where the thread is to be placed. But remember, the
thread should be placed in a group at the time of creating the thread only; else it is placed in
main thread group implicilty. Once a thread is allotted a thread group, throughout its life, the
group cannot be changed.
By placing the thread in a group, the advantage is, the thread attains the properties of the group
implicitly. For example, any thread belonging to main thread group attains a default priority of 5
because main group priority is set to 5. The java.lang package includes ThreadGroup class to
manipulate the threads with groups.

Advantages of ThreadGroup
It is learnt earlier that every thread should belong to a group. With thread group, all the threads
in a group can be assigned properties at a time instead of the laborious way of setting property
to each individual thread separately. Following are the benefits with thread groups.
All the threads can be given a common priority. For example, the common priority set to all
the threads of main group is 5.
All the threads of a group can be stopped, suspended or resumed at a time, but cannot be
started at a time ; each individual thread should be started separately.
Generally, thread groups are used very less in programming. The programmer leaves the thread
management to the JVM itself. SecurityManager class should be used to have extra control or
manipulation over the thread groups.
- See more at: http://way2java.com/multithreading/threadgroup-grouping-of-
threads/#sthash.Mao0TonI.dpuf

You might also like