⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javalang.doc19.html

📁 java语言规范
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html>
<head>
<title>The Java Language Specification The Package java.lang </title>
</head>
<body BGCOLOR=#eeeeff text=#000000 LINK=#0000ff VLINK=#000077 ALINK=#ff0000>
 
<a href="index.html">Contents</a> | <a href="javalang.doc18.html">Prev</a> | <a href="javalang.doc20.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<hr><br>
 
<a name="14469"></a>
<center><h1>20.21  The Class  <code>java.lang.ThreadGroup</code></h1></center>
<a name="26636"></a>
A thread group is a set of threads and thread groups. Every thread belongs to 
exactly one thread group, and every thread group but one (called the "system 
thread group") belongs to some other thread group. Thus thread groups form a 
tree with the system thread group at the root.
<p><a name="26640"></a>
Thread groups provide a way to manage threads and to impose security boundaries; for example, a thread may always create a new thread within its own thread group, but creating a thread in another thread group requires the approval of the security manager <a href="javalang.doc16.html#46274">(&#167;20.17)</a>, as does the creation of a new thread group.<p>
<pre><a name="14195"></a>public class <code><b>ThreadGroup</b></code> {
<a name="14196"></a>	public <code><b>ThreadGroup</b></code>(String name)
<a name="26901"></a>		throws SecurityException;
<a name="14197"></a>	public <code><b>ThreadGroup</b></code>(ThreadGroup parent, String name)
<a name="26896"></a>		throws <code>NullPointerExpression</code>, SecurityException,
<a name="27290"></a>			<code>IllegalThreadStateException</code>;
<a name="2786"></a>	public String <code><b>toString</b></code>();
<a name="27073"></a>	public final void <code><b>checkAccess</b></code>();
<a name="14198"></a>	public final String <code><b>getName</b></code>();
<a name="14199"></a>	public final ThreadGroup <code><b>getParent</b></code>();
<a name="2807"></a>	public final boolean <code><b>parentOf</b></code>(ThreadGroup g);
<a name="31409"></a>	public final void <code><b>stop</b></code>()
<a name="2798"></a>		throws <code>SecurityException</code>;
<a name="31412"></a>	public final void <code><b>suspend</b></code>()
<a name="2799"></a>		throws <code>SecurityException</code>;
<a name="31415"></a>	public final void <code><b>resume</b></code>()
<a name="2800"></a>		throws <code>SecurityException</code>;
<a name="2801"></a>	public final void <code><b>destroy</b></code>()
<a name="29311"></a>		throws <code>SecurityException</code>, <code>IllegalThreadStateException</code>;
<a name="2845"></a>	public final int <code><b>getMaxPriority</b></code>();
<a name="2846"></a>	public final void <code><b>setMaxPriority</b></code>(int <code>newMaxPriority</code>)
<a name="27567"></a>		throws <code>SecurityException</code>, IllegalArgumentException;
<a name="2847"></a>	public final boolean <code><b>isDaemon</b></code>();
<a name="2848"></a>	public final void <code><b>setDaemon</b></code>(boolean daemon)
<a name="27572"></a>		throws <code>SecurityException</code>;
<a name="29481"></a>	public 	int <code><b>threadsCount</b></code>();
<a name="29482"></a>	public int <code><b>allThreadsCount</b></code>()		;
<a name="29483"></a>	public int <code><b>groupsCount</b></code>();
<a name="29484"></a>	public int <code><b>allGroupsCount</b></code>();
<a name="29485"></a>	public Thread[] <code><b>threads</b></code>();
<a name="52486"></a>	public 	Thread[] <code><b>allThreads</b></code>();
<a name="29486"></a>	public ThreadGroup[] <code><b>groups</b></code>();
<a name="29488"></a>	public 	ThreadGroup[] <code><b>allGroups</b></code>();
<a name="14206"></a>	public int <code><b>activeCount</b></code>();															// deprecated
<a name="2792"></a>	public int <code><b>activeGroupCount</b></code>();															// deprecated
<a name="14207"></a>	public int <code><b>enumerate</b></code>(Thread list[]);															// deprecated
<a name="14208"></a>	public int <code><b>enumerate</b></code>(Thread list[],															// deprecated
<a name="29295"></a>			boolean recurse);
<a name="14210"></a>	public int <code><b>enumerate</b></code>(ThreadGroup list[]);															// deprecated
<a name="14211"></a>	public int <code><b>enumerate</b></code>(ThreadGroup list[],															// deprecated
<a name="29304"></a>			boolean recurse);
<a name="14216"></a>	public void <code><b>list</b></code>();
<a name="14217"></a>	public void <code><b>uncaughtException</b></code>(Thread t, Throwable e);
<a name="27427"></a>}
</pre><a name="27460"></a>
Every thread group has a <i>maximum priority</i>. The priority of a thread cannot be set <a href="javalang.doc18.html#14175">(&#167;20.20.23)</a> higher than the maximum priority of its thread group.<p>
<a name="27454"></a>
Each thread group may or may not be marked as a <i>daemon</i>. When a new <code>ThreadGroup</code> object is created, the newly created thread group is marked as a daemon thread group if and only if the thread group to which it belongs is currently a daemon thread group. But the daemonhood of a thread group <i>G</i> may be changed at any time by calling the <code>setDaemon</code> method of the <code>ThreadGroup</code> object that represents <i>G</i> (provided that the security manager <a href="javalang.doc16.html#14110">(&#167;20.17.12)</a> approves execution of the <code>setDaemon</code> operation).<p>
<a name="27433"></a>
Every thread group has a name, which is a <code>String</code>, for identification purposes. More than one thread group may have the same name.<p>
<a name="27437"></a>
Creation of a thread group requires the approval of the <code>checkAccess</code> method <a href="javalang.doc19.html#27041">(&#167;20.21.4)</a> of its proposed parent thread group, which forwards the decision to the security manager <a href="javalang.doc16.html#14109">(&#167;20.17.11)</a>.<p>
<a name="27429"></a>
<p><font size=+1><strong>20.21.1   </strong> <code>public <code><b>ThreadGroup</b></code>(String name)<br>throws SecurityException</code></font>
<p>
<a name="26914"></a>
First, the <code>checkAccess</code> method <a href="javalang.doc19.html#27041">(&#167;20.21.4)</a> of the thread group to which the current
thread belongs is called with no arguments.
<p><a name="26680"></a>
This constructor initializes a newly created <code>ThreadGroup</code> object so that it has the specified <code>name</code> as its name and belongs to the same thread group as the thread that is creating the new thread group.<p>
<a name="26865"></a>
This constructor has exactly the same effect as the explicit constructor call <code>this(Thread.currentThread().getThreadGroup(),</code> <code>name) </code><a href="javalang.doc19.html#2880">(&#167;20.21.2)</a>.<p>
<a name="2880"></a>
<p><font size=+1><strong>20.21.2   </strong> <code>public <code><b>ThreadGroup</b></code>(ThreadGroup parent, String name)<br>throws <code>NullPointerExpression</code>, SecurityException,  &#32; &#32; &#32;<code>IllegalThreadStateException</code></code></font>
<p>
<a name="26645"></a>
First, the <code>checkAccess</code> method <a href="javalang.doc19.html#27041">(&#167;20.21.4)</a> of the <code>parent</code> thread group is called 
with no arguments.
<p><a name="26871"></a>
If <code>parent</code> is <code>null</code>, then a <code>NullPointerExpression</code> is thrown. If <code>parent</code> is a <code>ThreadGroup</code> that has been destroyed by method <code>destroy</code> <a href="javalang.doc19.html#2888">(&#167;20.21.11)</a>, then an <code>IllegalThreadStateException</code> is thrown.<p>
<a name="26646"></a>
This constructor initializes a newly created <code>ThreadGroup</code> object so that it has the specified <code>name</code> as its name and belongs to the thread group represented by <code>parent</code>.<p>
<a name="26967"></a>
The maximum priority for the newly created thread group is set equal to the maximum priority of <code>parent</code>. The method <code>setMaxPriority</code> <a href="javalang.doc19.html#2890">(&#167;20.21.13)</a> may be used to change the maximum priority to a lower value.<p>
<a name="26971"></a>
The newly created thread group is initially marked as being a daemon thread group if and only <code>parent</code> is a daemon thread group. The method <code>setDaemon </code><a href="javalang.doc19.html#2892">(&#167;20.21.15)</a> may be used to change whether or not a thread group is a daemon thread group.<p>
<a name="2881"></a>
<p><font size=+1><strong>20.21.3   </strong> <code>public String <code><b>toString</b></code>()</code></font>
<p>
<a name="26657"></a>
The returned value is a concatenation of the following six strings:
<p><ul><a name="26662"></a>
<li>The name of the class of this thread group object
<a name="26663"></a>
<li><code>"[name="</code>
<a name="26723"></a>
<li>The name <a href="javalang.doc19.html#2882">(&#167;20.21.5)</a> of this thread group
<a name="26668"></a>
<li><code>",maxpri="</code>
<a name="26716"></a>
<li>The current maximum priority <a href="javalang.doc19.html#27398">(&#167;20.21.12)</a> for this thread group, as a decimal numeral
<a name="26676"></a>
<li><code>"]"</code>
</ul><a name="26704"></a>
All literal characters mentioned above are from the ASCII subset of Unicode.
<p><a name="26764"></a>
Overrides the <code>toString</code> method of <code>Object</code> <a href="javalang.doc1.html#14865">(&#167;20.1.3)</a>.<p>
<a name="27041"></a>
<p><font size=+1><strong>20.21.4   </strong> <code>public final void <code><b>checkAccess</b></code>()</code></font>
<p>
<a name="30819"></a>
If there is a security manager, its <code>checkAccess</code> method <a href="javalang.doc16.html#14110">(&#167;20.17.12)</a> is called with 
this <code>ThreadGroup</code> object as its argument. This may result in throwing, in the current
thread, a <code>SecurityException</code>.
<p><a name="27049"></a>
This method is called by methods <code>stop</code> <a href="javalang.doc19.html#2885">(&#167;20.21.8)</a>, <code>suspend</code> <a href="javalang.doc19.html#2886">(&#167;20.21.9)</a>, <code>resume</code> <a href="javalang.doc19.html#2887">(&#167;20.21.10)</a>, <code>destroy</code> <a href="javalang.doc19.html#2888">(&#167;20.21.11)</a>, <code>setMaxPriority</code> <a href="javalang.doc19.html#2890">(&#167;20.21.13)</a>, and <code>setDaemon</code> <a href="javalang.doc19.html#2892">(&#167;20.21.15)</a>.<p>
<a name="2882"></a>
<p><font size=+1><strong>20.21.5   </strong> <code>public final String <code><b>getName</b></code>()</code></font>
<p>
<a name="26688"></a>
The current name of this <code>ThreadGroup</code> object is returned as a <code>String</code>.
<p><a name="2883"></a>
<p><font size=+1><strong>20.21.6   </strong> <code>public final ThreadGroup <code><b>getParent</b></code>()</code></font>
<p>
<a name="27007"></a>
This method returns the <code>ThreadGroup</code> object that represents the thread group to 
which this thread group belongs. If this thread group is the system thread group, 
which is at the root of the thread group hierarchy, then <code>null</code> is returned.
<p><a name="2884"></a>
<p><font size=+1><strong>20.21.7   </strong> <code>public final boolean <code><b>parentOf</b></code>(ThreadGroup g)</code></font>
<p>
<a name="27003"></a>
This method returns <code>true</code> if and only if either this thread group is <code>g</code> or this method 
is <code>true</code> when applied to the parent of <code>g</code>. In other words, this method says whether 
this thread group is an ancestor of <code>g</code> or perhaps <code>g</code> itself.
<p><a name="26992"></a>
(This method arguably is misnamed; a more accurate, if clumsy and abstruse, name would be <code>parentOfReflexiveTransitiveClosure</code>.)<p>
<a name="2885"></a>
<p><font size=+1><strong>20.21.8   </strong> <code>public final void <code><b>stop</b></code>() throws SecurityException</code></font>
<p>
<a name="27139"></a>
First, the <code>checkAccess</code> method <a href="javalang.doc19.html#27041">(&#167;20.21.4)</a> of this <code>ThreadGroup</code> object is called 
with no arguments. This may result in a <code>SecurityException</code> being thrown (in 
the current thread).
<p><a name="27224"></a>
Every thread in this thread group or any of its subgroups is stopped. More precisely, &#32;the method <code>stop</code> is called for every <code>ThreadGroup</code> and every <code>Thread</code> <a href="javalang.doc18.html#8095">(&#167;20.20.15)</a> that belongs to this <code>ThreadGroup</code>.<p>
<a name="2886"></a>
<p><font size=+1><strong>20.21.9   </strong> <code>public final void <code><b>suspend</b></code>() throws SecurityException</code></font>
<p>
<a name="27189"></a>
First, the <code>checkAccess</code> method <a href="javalang.doc19.html#27041">(&#167;20.21.4)</a> of this <code>ThreadGroup</code> object is called 
with no arguments. This may result in a <code>SecurityException</code> being thrown (in 
the current thread).
<p><a name="27228"></a>
Every thread in this thread group or any of its subgroups is suspended. More precisely, the method <code>suspend</code> is called for every <code>ThreadGroup</code> and every <code>Thread</code> <a href="javalang.doc18.html#8097">(&#167;20.20.17)</a> that belongs to this <code>ThreadGroup</code>.<p>
<a name="2887"></a>
<p><font size=+1><strong>20.21.10   </strong> <code>public final void <code><b>resume</b></code>() throws SecurityException</code></font>
<p>
<a name="27196"></a>
First, the <code>checkAccess</code> method <a href="javalang.doc19.html#27041">(&#167;20.21.4)</a> of this <code>ThreadGroup</code> object is called 
with no arguments. This may result in a <code>SecurityException</code> being thrown (in 
the current thread).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -