📄 javalang.doc18.html
字号:
This constructor has exactly the same effect as the explicit constructor call <code>this(null,</code> <code>null,</code> <code>name)</code> <a href="javalang.doc18.html#14163">(§20.20.10)</a>.<p>
<a name="14158"></a>
<p><font size=+1><strong>20.20.6 </strong> <code>public <code><b>Thread</b></code>(Runnable runObject)</code></font>
<p>
<a name="7731"></a>
This constructor initializes a newly created <code>Thread</code> object so that it has the given
<code>runObject</code> as its separate run object, has a newly generated name, and belongs to
the same thread group as the thread that is creating the new thread.
<p><a name="7735"></a>
This constructor has exactly the same effect as the explicit constructor call <code>this(null,</code> <code>runObject,</code> <i>gname</i><code>)</code> <a href="javalang.doc18.html#14163">(§20.20.10)</a> where <i>gname</i> is a newly generated name. Automatically generated names are of the form <code>"Thread-"+</code><i>n</i> where <i>n</i> is an integer.<p>
<a name="2698"></a>
<p><font size=+1><strong>20.20.7 </strong> <code>public <code><b>Thread</b></code>(Runnable runObject, String name)</code></font>
<p>
<a name="7781"></a>
This constructor initializes a newly created <code>Thread</code> object so that it has the given
<code>runObject</code> as its separate run object, 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.
<p><a name="7785"></a>
This constructor has exactly the same effect as the explicit constructor call <code>this(null,</code> <code>runObject,</code> <code>name)</code> <a href="javalang.doc18.html#14163">(§20.20.10)</a>.<p>
<a name="7746"></a>
<p><font size=+1><strong>20.20.8 </strong> <code>public <code><b>Thread</b></code>(ThreadGroup group, String name)<br>throws SecurityException, <code>IllegalThreadStateException</code></code></font>
<p>
<a name="7887"></a>
First, if group is not <code>null</code>, the <code>checkAccess</code> method <a href="javalang.doc19.html#27041">(§20.21.4)</a> of that thread
group is called with no arguments.
<p><a name="7796"></a>
This constructor initializes a newly created <code>Thread</code> object so that it has no separate run object, has the specified <code>name</code> as its name, and belongs to the thread group referred to by <code>group</code> (but if <code>group</code> is <code>null</code>, then the new thread will belong to the same thread group as the thread that is creating the new thread).<p>
<a name="27327"></a>
If <code>group</code> is a <code>ThreadGroup</code> that has been destroyed by method <code>destroy</code> <a href="javalang.doc19.html#2888">(§20.21.11)</a>, then an <code>IllegalThreadStateException</code> is thrown.<p>
<a name="27331"></a>
This constructor has exactly the same effect as the explicit constructor call <code>Thread(group,</code> <code>null,</code> <code>name)</code> <a href="javalang.doc18.html#14163">(§20.20.10)</a>.<p>
<a name="14159"></a>
<p><font size=+1><strong>20.20.9 </strong> <code>public <code><b>Thread</b></code>(ThreadGroup group, Runnable runObject)<br>throws SecurityException, <code>IllegalThreadStateException</code></code></font>
<p>
<a name="7904"></a>
First, if group is not <code>null</code>, the <code>checkAccess</code> method <a href="javalang.doc19.html#27041">(§20.21.4)</a> of that thread
group is called with no arguments.
<p><a name="7812"></a>
This constructor initializes a newly created <code>Thread</code> object so that it has the given <code>runObject</code> as its separate run object, has a newly generated name, and belongs to the thread group referred to by <code>group</code> (but if <code>group</code> is <code>null</code>, then the new thread will belong to the same thread group as the thread that is creating the new thread).<p>
<a name="27338"></a>
If <code>group</code> is a <code>ThreadGroup</code> that has been destroyed by method <code>destroy</code> <a href="javalang.doc19.html#2888">(§20.21.11)</a>, then an <code>IllegalThreadStateException</code> is thrown.<p>
<a name="7816"></a>
This constructor has exactly the same effect as the explicit constructor call <code>this(group,</code> <code>runObject,</code> <i>gname</i><code>)</code> <a href="javalang.doc18.html#14163">(§20.20.10)</a> where <i>gname</i> is a newly generated name. Automatically generated names are of the form <code>"Thread-"+</code><i>n</i> where <i>n</i> is an integer.<p>
<a name="14163"></a>
<p><font size=+1><strong>20.20.10 </strong> <code>public <code><b>Thread</b></code>(ThreadGroup group, Runnable runObject,<br>      String name)<br>throws SecurityException, <code>IllegalThreadStateException</code></code></font>
<p>
<a name="7911"></a>
First, if group is not <code>null</code>, the <code>checkAccess</code> method <a href="javalang.doc19.html#27041">(§20.21.4)</a> of that thread
group is called with no arguments; this may result in a <code>SecurityException</code>
being thrown.
<p><a name="7848"></a>
This constructor initializes a newly created <code>Thread</code> object so that it has the given <code>runObject</code> as its separate run object, has the specified <code>name</code> as its name, and belongs to the thread group referred to by <code>group</code> (but if <code>group</code> is <code>null</code>, then the new thread will belong to the same thread group as the thread that is creating the new thread).<p>
<a name="27345"></a>
If <code>group</code> is a <code>ThreadGroup</code> that has been destroyed by method <code>destroy</code> <a href="javalang.doc19.html#2888">(§20.21.11)</a>, then an <code>IllegalThreadStateException</code> is thrown.<p>
<a name="7914"></a>
The priority of the newly created thread is set equal to the priority of the creating thread-that is, the currently running thread. The method <code>setPriority</code> <a href="javalang.doc18.html#14175">(§20.20.23)</a> may be used to change the priority to a new value.<p>
<a name="7919"></a>
The newly created thread is initially marked as being a daemon thread if and only if the thread creating it is a daemon thread. The method <code>setDaemon </code><a href="javalang.doc18.html#2861">(§20.20.25)</a> may be used to change whether or not a thread is a daemon.<p>
<a name="2680"></a>
<p><font size=+1><strong>20.20.11 </strong> <code>public String <code><b>toString</b></code>()</code></font>
<p>
<a name="7934"></a>
The returned value is a concatenation of the following seven strings:
<p><ul><a name="7935"></a>
<li><code>"Thread["</code>
<a name="7936"></a>
<li>The current name of the thread <a href="javalang.doc18.html#2868">(§20.20.19)</a>
<a name="7943"></a>
<li><code>","</code>
<a name="7947"></a>
<li>The current priority of the thread <a href="javalang.doc18.html#2819">(§20.20.22)</a>, as a decimal numeral
<a name="7963"></a>
<li><code>","</code>
<a name="26807"></a>
<li>The name <a href="javalang.doc19.html#2882">(§20.21.5)</a> of the thread group <a href="javalang.doc18.html#2870">(§20.20.21)</a> that contains this thread
<a name="7989"></a>
<li><code>"]"</code>
</ul><a name="26770"></a>
All literal characters mentioned above are from the ACSII subset of Unicode.
<p><a name="26754"></a>
Overrides the <code>toString</code> method of <code>Object</code> <a href="javalang.doc1.html#14865">(§20.1.3)</a>.<p>
<a name="8265"></a>
<p><font size=+1><strong>20.20.12 </strong> <code>public void <code><b>checkAccess</b></code>() throws SecurityException</code></font>
<p>
<a name="8272"></a>
If there is a security manager, its <code>checkAccess</code> method <a href="javalang.doc16.html#14109">(§20.17.11)</a> is called with
this <code>Thread</code> object as its argument. This may result in a <code>SecurityException</code>
being thrown in the current thread,.
<p><a name="8288"></a>
This method is called by methods <code>stop</code> of no arguments <a href="javalang.doc18.html#8095">(§20.20.15)</a>, <code>stop</code> of one argument <a href="javalang.doc18.html#8096">(§20.20.16)</a>, <code>suspend</code> <a href="javalang.doc18.html#8097">(§20.20.17)</a>, <code>resume</code> <a href="javalang.doc18.html#8098">(§20.20.18)</a>, <code>setName</code> <a href="javalang.doc18.html#2869">(§20.20.20)</a>, <code>setPriority</code> <a href="javalang.doc18.html#14175">(§20.20.23)</a>, and <code>setDaemon</code> <a href="javalang.doc18.html#2861">(§20.20.25)</a>.<p>
<a name="2686"></a>
<p><font size=+1><strong>20.20.13 </strong> <code>public void <code><b>run</b></code>()</code></font>
<p>
<a name="8016"></a>
The general contract of this method is that it should perform the intended action of
the thread.
<p><a name="8017"></a>
The <code>run</code> method of class <code>Thread</code> simply calls the <code>run</code> method of the separate run object, if there is one; otherwise, it does nothing.<p>
<a name="8093"></a>
<p><font size=+1><strong>20.20.14 </strong> <code>public void <code><b>start</b></code>()<br>throws IllegalThreadStateException</code></font>
<p>
<a name="8111"></a>
Invoking this method causes this thread to begin execution; this thread calls the
<code>run</code> method of this <code>Thread</code> object. The result is that two threads are running concurrently:
the current thread (which returns from the call to the <code>start</code> method)
and the thread represented by this <code>Thread</code> object (which executes its <code>run</code> method).
<p><a name="8095"></a>
<p><font size=+1><strong>20.20.15 </strong> <code>public final void <code><b>stop</b></code>()<br>throws SecurityException</code></font>
<p>
<a name="8132"></a>
First, the <code>checkAccess</code> method <a href="javalang.doc18.html#8265">(§20.20.12)</a> of this <code>Thread</code> object is called with
no arguments. This may result in throwing a <code>SecurityException</code> (in the current
thread).
<p><a name="8155"></a>
This thread is forced to complete abnormally whatever it was doing and to throw a <code>ThreadDeath</code> object as an exception. For this purpose, this thread is resumed if it had been suspended, and is awakened if it had been asleep.<p>
<a name="8228"></a>
It is permitted to stop a thread that has not yet been started. If the thread is eventually started, it will immediately terminate.<p>
<a name="8162"></a>
User code should not normally try to catch <code>ThreadDeath</code> unless some extraordinary cleanup operation is necessary (note that the process of throwing a <code>ThreadDeath</code> exception <i>will</i> cause <code>finally</code> clauses of <code>try</code> statements to be executed before the thread officially dies). If a <code>catch</code> clause does catch a <code>ThreadDeath</code> object, it is important to rethrow the object so that the thread will actually die. The top-level error handler that reacts to otherwise uncaught exceptions will not print a message or otherwise signal or notify the user if the uncaught exception is an instance of <code>ThreadDeath</code>.<p>
<a name="8096"></a>
<p><font size=+1><strong>20.20.16 </strong> <code>public final void <code><b>stop</b></code>(Throwable thr)<br>throws SecurityException, NullPointerException</code></font>
<p>
<a name="8139"></a>
First, the <code>checkAccess</code> method <a href="javalang.doc18.html#8265">(§20.20.12)</a> of this <code>Thread</code> object is called with
no arguments. This may result in throwing a <code>SecurityException</code> (in the current
thread).
<p><a name="8151"></a>
If the argument <code>thr</code> is null, then a <code>NullPointerException</code> is thrown (in the current thread).<p>
<a name="26383"></a>
This thread is forced to complete abnormally whatever it was doing and to throw the <code>Throwable</code> object <code>thr</code> as an exception. For this purpose, this thread is resumed if it had been suspended, and is awakened if it had been asleep. This is an unusual action to take; normally, the <code>stop</code> method that takes no arguments <a href="javalang.doc18.html#8095">(§20.20.15)</a> should be used.<p>
<a name="8233"></a>
It is permitted to stop a thread that has not yet been started. If the thread is eventually started, it will immediately terminate.<p>
<a name="8097"></a>
<p><font size=+1><strong>20.20.17 </strong> <code>public final void <code><b>suspend</b></code>()<br>throws SecurityException</code></font>
<p>
<a name="8198"></a>
First, the <code>checkAccess</code> method <a href="javalang.doc18.html#8265">(§20.20.12)</a> of this <code>Thread</code> object is called with
no arguments. This may result in throwing a <code>SecurityException</code> (in the current
thread).
<p><a name="8238"></a>
If this thread is alive <a href="javalang.doc18.html#8259">(§20.20.26)</a>, it is suspended and makes no further progress unless and until it is resumed. It is permitted to suspend a thread that is already in a suspended state; it remains suspended. Suspensions are not tallied; even if a thread is suspended more than once, only one call to <code>resume</code> is required to resume it.<p>
<a name="8098"></a>
<p><font size=+1><strong>20.20.18 </strong> <code>public final void <code><b>resume</b></code>()<br>throws SecurityException</code></font>
<p>
<a name="8205"></a>
First, the <code>checkAccess</code> method <a href="javalang.doc18.html#8265">(§20.20.12)</a> of this <code>Thread</code> object is called with
no arguments. This may result in throwing a <code>SecurityException</code> (in the current
thread).
<p><a name="8247"></a>
If this thread is alive <a href="javalang.doc18.html#8259">(§20.20.26)</a> but suspended, it is resumed and is permitted to make progress in its execution. It is permitted to resume a thread that has never been suspended or has already been resumed; it continues to make progress in its execution. Resumptions are not tallied; even if a thread is resumed more than once, only one call to <code>suspend</code> is required to suspend it.<p>
<a name="2868"></a>
<p><font size=+1><strong>20.20.19 </strong> <code>public final String <code><b>getName</b></code>()</code></font>
<p>
<a name="8018"></a>
The current name of this <code>Thread</code> object is returned as a <code>String</code>.
<p><a name="2869"></a>
<p><font size=+1><strong>20.20.20 </strong> <code>public final void <code><b>setName</b></code>(String name)<br>throws SecurityException</code></font>
<p>
<a name="8023"></a>
First, the <code>checkAccess</code> method <a href="javalang.doc18.html#8265">(§20.20.12)</a> of this <code>Thread</code> object is called with
no arguments. This may result in throwing a <code>SecurityException</code> (in the current
thread).
<p><a name="8338"></a>
The name of this <code>Thread</code> object is changed to be equal to the argument <code>name</code>.<p>
<a name="2870"></a>
<p><font size=+1><strong>20.20.21 </strong> <code>public final ThreadGroup <code><b>getThreadGroup</b></code>()</code></font>
<p>
<a name="26407"></a>
If this thread is alive, this method returns a reference to the <code>ThreadGroup</code> object
that represents the thread group to which this thread belongs. If this thread has
died (has been stopped), this method returns <code>null</code>.
<p><a name="2819"></a>
<p><font size=+1><strong>20.20.22 </strong> <code>public final int <code><b>getPriority</b></code>()</code></font>
<p>
<a name="8340"></a>
The current priority of this <code>Thread</code> object is returned.
<p><a name="14175"></a>
<p><font size=+1><strong>20.20.23 </strong> <code>public final void <code><b>setPriority</b></code>(int newPriority)<br>throws SecurityException, IllegalArgumentException</code></font>
<p>
<a name="8352"></a>
First, the <code>checkAccess</code> method <a href="javalang.doc18.html#8265">(§20.20.12)</a> of this <code>Thread</code> object is called with
no arguments. This may result in throwing a <code>SecurityException</code> (in the current
thread).
<p><a name="8393"></a>
If the <code>newPriority</code> argument is less than <code>MIN_PRIORITY</code> <a href="javalang.doc18.html#14148">(§20.20.1)</a> or greater than <code>MAX_PRIORITY</code> <a href="javalang.doc18.html#2662">(§20.20.2)</a>, then an <code>IllegalArgumentException</code> is thrown.<p>
<a name="8398"></a>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -