📄 04-01.html
字号:
<option value="">----------- <option value="/reference/whatsnew.html">New Arrivals </SELECT> </font> </td> </tr></table></form> <!-- LEFT NAV SEARCH END --><table border="0" cellspacing="0" cellpadding="0"> <tr> <td><a href="/desktop/"><img src="/images/desktop_icona.gif" border=0 alt="Go to ITKnowledge Academic"></a><br><br></td> </tr></table> <!-- BEGIN TEXT LINKS --><!-- END TEXT LINKS --><!-- END LEFT NAVBAR --><!-- END LEFT NAVBAR --> <td width="15"><img src="/images/dotclear.gif" width="15" alt="" border="0"></td><!-- end of ITK left NAV --><!-- begin main content --> <td width="100%" valign="top" align="left"> <br><!-- END SUB HEADER --><!-- Created by dB Page Builder. http://www.pchelponline.com/bluestem -->
<!--Begin Content Column -->
<TABLE border=0 cellspacing=0 cellpadding=0>
<tr>
<td width=75 valign=top>
<img src="/images/sm_covers/1562438425.gif" width=60 height=73 alt="Mastering Java Threads" border="1">
</td>
<td align="left">
<font face="arial, helvetica" size="-1" color="#336633"><b>Mastering Java Threads</b></font>
<br>
<font face="arial, helvetica" size="-1"><i>by Marc Adler and David Herst</i>
<br>
DDC Publishing, Inc.
<br>
<b>ISBN:</b> 1562438425<b> Pub Date:</b> 05/01/99</font> <A HREF="http://www.digitalguru.com/dgstore/product.asp?isbn=1562438425&ac%5Fid=28" TARGET="anotherwindows"><img src="/images/buyit.gif" width=64 height=23 hspace="5" align="middle" alt="Buy It" border="0"></a>
</td>
</tr>
</table>
<P>
<form name="advanced" method="POST" action="http://ewsearch.earthweb.com:80/jsp/k2search/ewintrak2search_p2.jsp" onSubmit=" return checkForQuery(this); ">
<INPUT type="hidden" name="collection" value="corpitk_p2">
<INPUT type="hidden" name="altcoll" value="allbooks_p2">
<INPUT type="hidden" name="hl" value="on">
<INPUT name="sortspec" type=hidden value="score desc">
<INPUT name="fields" type=hidden value="vdkvgwkey score vstitle vsisbn vsauthor vspublisher vspubdate">
<INPUT name="imageprefix" type=hidden value="http://academic.itknowledge.com">
<INPUT name="ssiFolder" type=hidden value="itkaca">
<INPUT name="topics" type=hidden value="itk_academic">
<INPUT type="hidden" name="bookid" value="t_1562438425">
<font face="arial, helvetica" size=2><b>Search this book:</b></font><br>
<INPUT NAME="query" size=25 VALUE=""> <input type="image" width=28 height=23 border=0 value="Go" name="Go" src="/images/go.gif" align=absmiddle>
</form>
<!-- Empty Reference Subhead -->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch03/03-01.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="04-02.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 4<BR>The Thread Class in Detail
</FONT></H2>
<P><BIG><B>Lesson Topics</B></BIG></P>
<DL>
<DD><B>•</B> Variables
<DD><B>•</B> Behind the Scenes: The Thread Class in C
</DL>
<H3><A NAME="Heading2"></A><FONT COLOR="#000077">Variables</FONT></H3>
<P>All variables deal with the priority of the thread.
</P>
<DL>
<DD><B>•</B> <B>public final static int MIN_PRIORITY:</B> the minimum priority that a Thread can have. The most minimal priority is equal to 1.
<DD><B>•</B> <B>public final static int NORM_PRIORITY:</B> the default priority that is assigned to a Thread. The default priority is equal to 5.
<DD><B>•</B> <B>public final static int MAX_PRIORITY:</B> the maximum priority that a Thread can have. The max priority value a Thread can have is 10.
</DL>
<H4 ALIGN="LEFT"><A NAME="Heading3"></A><FONT COLOR="#000077">Methods</FONT></H4>
<TABLE WIDTH="100%" BORDER>
<TR>
<CAPTION VALIGN="BOTTOM"><B>Table 4-1: Thread methods</B></CAPTION>
</TR>
<TR>
<TH ALIGN="CENTER" VALIGN="TOP" WIDTH="40%">Constructor</TH>
<TH ALIGN="CENTER" VALIGN="TOP" WIDTH="60%">Description</TH>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>Thread()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Constructs a new Thread.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>Thread(Runnable)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Constructs a new Thread; applies the <B>run()</B> method of the specified target.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>Thread(ThreadGroup, Runnable)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Constructs a new Thread in the specified Thread group; applies the <B>run()</B> method of the specified target.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>Thread(String)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Constructs a new Thread with the specified name.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>Thread(ThreadGroup, String)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Constructs a new Thread in the specified Thread group with the specified name.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>Thread(Runnable, String)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Constructs a new Thread with the specified name and applies the <B>run()</B> method of the specified target.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>Thread(ThreadGroup, Runnable, String)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Constructs a new Thread in the specified Thread group with the specified name and applies the <B>run()</B> method of the specified target.</TD>
</TR>
</TABLE>
<P><FONT SIZE="+1"><B>Thread Body</B></FONT></P>
<P>The <B>run()</B> method is the actual body of this Thread.</P>
<P><FONT SIZE="+1"><B>Methods That Query & Change the State of a Thread</B></FONT></P>
<TABLE WIDTH="100%" BORDER>
<TR>
<CAPTION VALIGN="BOTTOM"><B>Table 4-2: Methods that query and change the state of a thread</B></CAPTION>
</TR>
<TR>
<TH ALIGN="CENTER" VALIGN="TOP" WIDTH="30%">Method</TH>
<TH ALIGN="CENTER" VALIGN="TOP" WIDTH="70%">Description</TH>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>destroy()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Destroy a threads without any cleanup.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>isAlive()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Returns a boolean indicating if the Thread is active. A thread is active if it is in Runnable or Not Runnable state. It is not active if it is in a Dead or New state.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>resume()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Resumes this Thread execution.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>sleep(long)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Causes the currently executing Thread to sleep for the specified number of milliseconds.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>sleep(long, int)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Sleep, in milliseconds and additional nanosecond.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>start()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Starts this Thread.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>stop()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Stops a Thread asynchronously.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>stop(Throwable)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Stops a Thread asynchronously by throwing an object.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>suspend()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Suspends this Thread’s execution.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>yield()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Causes the currently executing Thread object to yield.</TD>
</TR>
</TABLE>
<P><FONT SIZE="+1"><B>Thread Attributes</B></FONT></P>
<TABLE WIDTH="100%" BORDER>
<TR>
<CAPTION VALIGN="BOTTOM"><B>Table 4-3: Thread attributes</B></CAPTION>
</TR>
<TR>
<TH ALIGN="CENTER" VALIGN="TOP" WIDTH="30%">Attribute</TH>
<TH ALIGN="CENTER" VALIGN="TOP" WIDTH="70%">Description</TH>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>countStackFrames()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Returns the number of stack frames in this Thread.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>getName()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Gets and returns this Thread’s name.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>getThreadGroup()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Gets and returns this Thread group.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>setName(String)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Sets the Thread’s name.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>toString()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Returns a String representation of the Thread, including the thread’s name, priority, and thread group.</TD>
</TR>
</TABLE>
<P><FONT SIZE="+1"><B>Priority</B></FONT></P>
<TABLE WIDTH="100%" BORDER>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP" WIDTH="30%"><B>getPriority()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH="70%">Gets and returns the Thread’s priority.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>setPriority(int)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Sets the Thread’s priority.</TD>
</TR>
</TABLE>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch03/03-01.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="04-02.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright © <a href="/reference/ddc00001.html">DDC Publishing</a></font></div>
<!-- all of the reference materials (books) have the footer and subfoot reveresed --><!-- reference_subfoot = footer --><!-- reference_footer = subfoot --><!-- BEGIN SUB FOOTER --> <br> <img src="/images/dotclear.gif" width="5" height="7" border="0"> </TD> </TR> </TABLE> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" width="160"><img src="/images/bot_curve.jpg" width="160" alt="" border="0"></td> <td align="left" valign="top" nowrap><a href="/"><img src="/images/top_tabs/home_bot.gif" alt="home" border="0"></a><!-- <a href="/content/corp.html"><img src="/images/top_tabs/subscribe_bot.gif" alt="Subscribe" border="0"></a> --><a href="/search/"><img src="/images/top_tabs/search_bot.gif" alt="search" border="0"></a><a href="/faq/faq.html"><img src="/images/top_tabs/faq_bot.gif" alt="faq" border="0"></a><a href="/sitemap.html"><img src="/images/top_tabs/sitemap_bot.gif" alt="sitemap" border="0"></a><a href="/contactus.html"><img src="/images/top_tabs/contact_us_bot.gif" alt="contactus" border="0"></a><img src="/images/dotclear.gif" width=260 height="1" alt="" border="0"></td> </tr></table> <table width="100%" bgcolor="#003366" border=0 cellpadding=0 cellspacing=0> <tr> <td align="left" width=145><img src="/images/dotclear.gif" width=145 height="1" alt="" border="0"></td> <!-- END SUB FOOTER -->
<!-- all of the books have the footer and subfoot reveresed --><!-- reference_subfoot = footer --><!-- reference_footer = subfoot --><!-- FOOTER --> <td align="left" bgcolor="#003366"><table border="0" cellspacing="10" cellpadding="5"><tr><td align="center"><font face="arial, helvetica" size="1" color="#cccccc"><b><a href="/products.html"><font color="#0099CC">Products</font></a> | <a href="/contactus.html"><font color="#0099CC">Contact Us</font></a> | <a href="http://www.earthweb.com/dlink.corp|about_us-jhtml.72.0.-.0.jhtml" target="resource window"><font color="#0099CC">About Us</font></a> | <a href="http://www.earthweb.com/dlink.corp|privacy-jhtml.72.0.-.-.jhtml" target="resource window"><font color="#0099CC">Privacy</font></a> | <a href="http://www.itmarketer.com/" target="resource window"><font color="#0099CC">Ad Info</font></a> | <!--<a href="/consortia/"><font color="#0099CC">Consortia</font></a> | --><a href="/"><font color="#0099CC">Home</font></a></b><br><br>Use of this site is subject to certain <a href="/agreement.html"><font color="#0099CC">Terms & Conditions</font></a>, <a href="/copyright.html"><font color="#0099CC">Copyright © 1996-2000 EarthWeb Inc.</font></a> All rights reserved. Reproduction in whole or in part in any form or medium without express written <a href="http://www.earthweb.com/dlink.corp|permissions-jhtml.72.0.-.-.jhtml" target="resource window"><font color="#0099CC">permission</font></a> of EarthWeb is prohibited. Read EarthWeb's <A HREF="http://www.earthweb.com/dlink.corp|privacy-jhtml.72.0.-.-.jhtml" target="resource window"><font color="#0099CC">privacy</font></A> statement.</font><br><br></td></tr></table><a href="AITK1a2b3c4d5e6f7g8h9idefcon4.html"><img src="/images/dotclear.gif" border="0" height="1" width="1" align="left"></a></td> </tr></table><!--DoubleClick Ad BEGIN--><SCRIPT LANGUAGE="JavaScript"><!--document.write('<layer src="http://ad.doubleclick.net/adl/academic.itknowledge.com/homepage;cat=homepage;cat=enterprise;cat=education;cat=it_training;ord=' + ord + '" width="468" height="60" visibility="hide" onload="moveToAbsolute(ph1.pageX, ph1.pageY); visibility=\'show\';" clip="468,60"></layer>');document.write('<LAYER SRC="http://ad.doubleclick.net/adl/itkaca.earthweb.dart/b_aca_soft_dev;a=b_aca_soft_dev4;sz=160x60;ord=' + ord + '" width=160 height=60 visibility="hidden" onLoad="moveToAbsolute(layer1.pageX,layer1.pageY);clip.height=60;clip.width=160; visibility=\'show\';"></LAYER>');//--></SCRIPT> <!--DoubleClick Ad END--></BODY></HTML><!-- END FOOTER -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -