📄 java08_02.htm
字号:
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> boolean</code></font></td>
<td><code><b>isDaemon</b>()</code><br>
Tests if
this thread is a daemon thread.</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> boolean</code></font></td>
<td><code><b>isInterrupted</b>()</code><br>
Tests
whether this thread has been interrupted.</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> void</code></font></td>
<td><code><b>join</b>()</code><br>
Waits for
this thread to die.</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> void</code></font></td>
<td><code><b>join</b>(long millis)</code><br>
Waits at
most <code>millis</code> milliseconds for this thread to die.</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> void</code></font></td>
<td><code><b>join</b>(long millis,
int nanos)</code><br>
Waits at
most <code>millis</code> milliseconds plus <code>nanos</code>
nanoseconds for this thread to die.</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> void</code></font></td>
<td><code><b>resume</b>()</code><br>
<b>Deprecated.</b> <i>This
method exists solely for use with <code>suspend()</code>,
which has been deprecated because it is deadlock-prone. For more
information, see Why
are Thread.stop, Thread.suspend and Thread.resume Deprecated?.</i></td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> void</code></font></td>
<td><code><b>run</b>()</code><br>
如果类是使用单独的Runnable对象构造的,将调用Runnable对象的run方法,否则本方法不做任何事情就返回了。<br>
如果是子类继承Thread类,请务必实现本方法以覆盖父类的run方法。</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> void</code></font></td>
<td><code><b>setContextClassLoader</b>(ClassLoader cl)</code><br>
Sets the
context ClassLoader for this Thread.</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> void</code></font></td>
<td><code><b>setDaemon</b>(boolean on)</code><br>
Marks this
thread as either a daemon thread or a user thread.</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> void</code></font></td>
<td><code><b>setName</b>(String name)</code><br>
Changes the
name of this thread to be equal to the argument <code>name</code>.</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> void</code></font></td>
<td><code><b>setPriority</b>(int newPriority)</code><br>
改变线程的优先级,Java定义了三种级别:Thread.MIN_PRIORITY,Thread.MAX_PRIORITY
, 和Thread.NORM_PRIORITY</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code>static void</code></font></td>
<td><code><b>sleep</b>(long millis)</code><br>
正在运行的线程睡眠(暂停),参数millis指定毫秒数。</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code>static void</code></font></td>
<td><code><b>sleep</b>(long millis,
int nanos)</code><br>
正在运行的线程睡眠(暂停),millis指定毫秒数,nanos指定纳秒数</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> void</code></font></td>
<td><code><b>start</b>()</code><br>
Causes this
thread to begin execution; the Java Virtual Machine calls the <code>run</code>
method of this thread.</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> void</code></font></td>
<td><code><b>stop</b>()</code><br>
<b>Deprecated.</b> <i>This
method is inherently unsafe. Stopping a thread with Thread.stop causes
it to unlock all of the monitors that it has locked (as a natural
consequence of the unchecked <code>ThreadDeath</code> exception
propagating up the stack). If any of the objects previously protected by
these monitors were in an inconsistent state, the damaged objects become
visible to other threads, potentially resulting in arbitrary behavior.
Many uses of <code>stop</code> should be replaced by code that simply
modifies some variable to indicate that the target thread should stop
running. The target thread should check this variable regularly, and
return from its run method in an orderly fashion if the variable
indicates that it is to stop running. If the target thread waits for
long periods (on a condition variable, for example), the <code>interrupt</code>
method should be used to interrupt the wait. For more information, see Why
are Thread.stop, Thread.suspend and Thread.resume Deprecated?.</i></td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> void</code></font></td>
<td><code><b>stop</b>(Throwable obj)</code><br>
<b>Deprecated.</b> <i>This
method is inherently unsafe. See <code>stop()</code>
(with no arguments) for details. An additional danger of this method is
that it may be used to generate exceptions that the target thread is
unprepared to handle (including checked exceptions that the thread could
not possibly throw, were it not for this method). For more information,
see Why
are Thread.stop, Thread.suspend and Thread.resume Deprecated?.</i></td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> void</code></font></td>
<td><code><b>suspend</b>()</code><br>
<b>Deprecated.</b> <i>This
method has been deprecated, as it is inherently deadlock-prone. If the
target thread holds a lock on the monitor protecting a critical system
resource when it is suspended, no thread can access this resource until
the target thread is resumed. If the thread that would resume the target
thread attempts to lock this monitor prior to calling <code>resume</code>,
deadlock results. Such deadlocks typically manifest themselves as
"frozen" processes. For more information, see Why
are Thread.stop, Thread.suspend and Thread.resume Deprecated?.</i></td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code> String</code></font></td>
<td><code><b>toString</b>()</code><br>
Returns a
string representation of this thread, including the thread's name,
priority, and thread group.</td>
</tr>
<tr class="TableRowColor" >
<td vAlign="top" align="right" width="1%"><font size="-1"><code>static void</code></font></td>
<td><code><b>yield</b>()</code><br>
正在运行的线程暂停,同时允许其它的线程运行</td>
</tr>
</tbody>
</table>
<p align="left"> </p>
<p align="left"><a href="index.htm">回目录</a> <a href="java08_01.htm">上一课</a>
<a href="java08_03.htm">下一课</a></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -