ThreadGroup Class - Methods that Operate on the Group

The ThreadGroup class supports several attributes that are set and retrieved from the group as a whole. These attributes include the maximum priority that any thread within the group can have, whether the group is a "daemon" group, the name of the group, and the parent of the group.

The methods that get and set ThreadGroup attributes operate at the group level. They inspect or change the attribute on the ThreadGroup object, but do not affect any of the threads within the group. The following is a list of ThreadGroup methods that operate at the group level:
  • getMaxPriority and setMaxPriority
  • getDaemon and setDaemon
  • getName
  • getParent and parentOf
  • toString
For example, when you use setMaxPriority to change a group's maximum priority, you are only changing the attribute on the group object; you are not changing the priority of any of the threads within the group. Consider the following program that creates a group and a thread within that group:

class MaxPriorityTest {
public static void main(String[] args) {

ThreadGroup groupNORM = new ThreadGroup(
"A group with normal priority");
Thread priorityMAX = new Thread(groupNORM,
"A thread with maximum priority");

// set Thread's priority to max (10)

// set ThreadGroup's max priority to normal (5)

System.out.println("Group's maximum priority = " +
System.out.println("Thread's priority = " +

When the ThreadGroup groupNORM is created, it inherits its maximum priority attribute from its parent thread group. In this case, the parent group priority is the maximum (MAX_PRIORITY) allowed by the Java runtime system. Next the program sets the priority of the priorityMAX thread to the maximum allowed by the Java runtime system. Then the program lowers the group's maximum to the normal priority (NORM_PRIORITY). The setMaxPriority method does not affect the priority of the priorityMAX thread, so that at this point, the priorityMAX thread has a priority of 10, which is greater than the maximum priority of its group, groupNORM. This is the output from the program:
Group's maximum priority = 5
Thread's priority = 10

As you can see a thread can have a higher priority than the maximum allowed by its group as long as the thread's priority is set before the group's maximum priority is lowered. A thread group's maximum priority is used to limit a thread's priority when the thread is first created within a group or when you use setPriority to change the thread's priority. Note that setMaxPriority does change the maximum priority of all of its descendant-threadgroups.

Similarly, a group's daemon status applies only to the group. Changing a group's daemon status does not affect the daemon status of any of the threads in the group. Furthermore, a group's daemon status does not in any way imply the daemon status of its threads--you can put any thread within a daemon thread group. The daemon status of a thread group simply indicates that the group will be destroyed when all of its threads have been terminated.

Related Posts:-

People who read this post also read :


Do this hack to drop 2lb of fat in 8 hours

Over 160 000 men and women are trying a simple and secret "water hack" to drop 1-2 lbs each night in their sleep.

It's very easy and it works all the time.

Here's how you can do it yourself:

1) Go grab a glass and fill it up half glass

2) Proceed to use this strange HACK

and become 1-2 lbs skinnier in the morning!

Your Affiliate Profit Machine is ready -

Plus, getting it set up is as easy as 1--2--3!

This is how it works...

STEP 1. Choose which affiliate products you want to promote
STEP 2. Add push button traffic (it takes JUST 2 minutes)
STEP 3. Watch the affiliate system grow your list and sell your affiliate products on it's own!

Are you ready to start making money?

Check it out here

Water Hack Burns 2lb of Fat OVERNIGHT

At least 160 000 men and women are losing weight with a simple and secret "liquid hack" to burn 2 lbs each night in their sleep.

It's scientific and it works with anybody.

This is how to do it yourself:

1) Grab a drinking glass and fill it up half the way

2) Proceed to use this amazing hack

so you'll become 2 lbs skinnier the next day!

As claimed by Stanford Medical, It is indeed the ONLY reason this country's women live 10 years more and weigh on average 42 lbs less than we do.

(And actually, it is not related to genetics or some secret diet and absolutely EVERYTHING around "how" they eat.)

P.S, I said "HOW", not "WHAT"...

CLICK this link to reveal if this easy questionnaire can help you unlock your true weight loss potential

Post a Comment


Twitter Delicious Facebook Digg Stumbleupon Favorites More