Java Reference
In-Depth Information
14.11. Thread Management, Security, and THReadGroup
When you're programming multiple threadssome of them created by lib-
rary classesit can be useful to organize them into related groups, manage
the threads in a group as a unit, and, if necessary, place limitations on
what threads in different groups can do.
Threads are organized into thread groups for management and security
reasons. A thread group can be contained within another thread group,
providing a hierarchyoriginating with the top-level or system thread
group. Threads within a group can be managed as a unit, for example,
by interrupting all threads in the group at once, or placing a limit on
the maximum priority of threads in a group. The thread group can also
be used to define a security domain. Threads within a thread group
can generally modify other threads in that group, including any threads
farther down the hierarchy. In this context "modifying" means invoking
any method that could affect a thread's behaviorsuch as changing its pri-
ority, or interrupting it. However, an application can define a security
policy that prevents a thread from modifying threads outside of its group.
Threads within different thread groups can also be granted different per-
missions for performing actions within the application, such as perform-
ing I/O.
Generally speaking, security-sensitive methods always check with any
installed security manager before proceeding. If the security policy in
force forbids the action, the method throws a SecurityException . By de-
fault there is no security manager installed when an application starts.
If your code is executed in the context of another application, however,
such as an applet within a browser, you can be fairly certain that a se-
curity manager has been installed. Actions such as creating threads, con-
trolling threads, performing I/O, or terminating an application, are all se-
curity sensitive. For further details, see " Security " on page 677 .
Every thread belongs to a thread group. Each thread group is represen-
ted by a ThreadGroup object that describes the limits on threads in that
group and allows the threads in the group to be interacted with as a
group. You can specify the thread group for a new thread by passing it
to the thread constructor. By default each new thread is placed in the
 
Search WWH ::




Custom Search