Java Reference
In-Depth Information
um priority, any attempt to set a thread priority higher than the thread
group's maximum is silently reduced to that maximum. Existing threads
are not affected by this invocation. To ensure that no other thread in the
group will ever have a higher priority than that of a particular thread,
you can set that thread's priority and then set the group's maximum
priority to be less than that. The limit also applies to the thread group
itself. Any attempt to set a new maximum priority for the group that is
higher than the current maximum will be silently reduced.
static synchronized void
maxThread(Thread thr, int priority)
{
ThreadGroup grp = thr.getThreadGroup();
thr.setPriority(priority);
grp.setMaxPriority(thr.getPriority() - 1);
}
This method works by setting the thread's priority to the desired value
and then setting the group's maximum allowable priority to less than
the thread's priority. The new group maximum is set to one less than
the thread's actual prioritynot to
priority- 1
because an existing group
maximum might limit your ability to set the thread to that priority. Of
course, this method assumes that no thread in the group already has a
higher priority.
ThreadGroup
supports the following constructors and methods:
public
ThreadGroup(String name)
Creates a new
ThreadGroup
. Its parent will be the
ThreadGroup
of
the current thread. Like
Thread
names, the name of a group is
not used by the runtime systembut it can be
null
.
public
ThreadGroup(ThreadGroup parent, String name)