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

📄 03-01.html

📁 master java threads
💻 HTML
📖 第 1 页 / 共 2 页
字号:
			<option value="vstitle" SELECTED>Title			<option value="vsauthor">Author			<option value="vspublisher">Publisher			<option value="vsisbn">ISBN						</SELECT><br><br></font>			</td>			</tr></table></form><form action="" name="catlist">	<table width="145" border="0" cellpadding="0" cellspacing="0">							<tr>			<td valign="top">			<img src="/images/jump_topica.gif" width="145" alt="" border="0">			</td>			</tr>			<tr>			<td width="145">					        	<font face="Arial,helvetica" size="1">				&nbsp;&nbsp;<SELECT NAME="cat" onChange='top.location.href=this.options[selectedIndex].value;' style="font-size: 10; font-family: sans-serif;">                        <option value="" selected>Please Select                        <option value="">-----------						<option value="/reference/dir.1-busman.html">Business &amp; IT Mgmt						<option value="/reference/dir.2-certification.html">Certification &amp; Training                       						<option value="/reference/dir.3-databaseanderp.html">Database &amp; ERP                        <option value="/reference/dir.4-desktopapps.html">Desktop Apps                        <option value="/reference/dir.5-desktoppubanddesign.html">Graphic Design                        <option value="/reference/dir.6-generalinternet.html">General Internet                        <option value="/reference/dir.7-hardwareandos.html">Hardware &amp; OS                        <option value="/reference/dir.8-ibmredbooks.html">IBM RedBooks                        <option value="/reference/dir.9-networktelcom.html">Network &amp; Telecom						<option value="/reference/dir.10-websoftwaredev.html">Web &amp; Software Dev						<option value="/reference/dir.11-careers.html">Careers                        <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>&nbsp;1562438425<b>&nbsp;&nbsp;&nbsp;Pub Date:</b>&nbsp;05/01/99</font>&nbsp;&nbsp;<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="">&nbsp;<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="../ch02/02-01.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch04/04-01.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 3<BR>The Runnable Interface
</FONT></H2>
<P><BIG><B>Lesson Topics</B></BIG></P>
<DL>
<DD><B>&#149;</B>&nbsp;&nbsp;The Runnable Interface
</DL>
<H3><A NAME="Heading2"></A><FONT COLOR="#000077">The Runnable Interface</FONT></H3>
<P>The Java declaration of the Runnable interface is as follows:
</P>

<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD>
<!-- CODE SNIP //-->
<PRE>
public interface Runnable extends Object
</PRE>
<!-- END CODE SNIP //-->
</TD>
</TR>
</TABLE>

<H4 ALIGN="LEFT"><A NAME="Heading3"></A><FONT COLOR="#000077">Java Interface Defined</FONT></H4>
<P>As you already learned, an <I>interface</I> in Java is an abstraction of a class (such as an abstract class in C<SMALL>&#43;&#43;</SMALL>). If your class implements an interface, you are responsible for implementing the methods that the interface defines. In the case of the Runnable interface, you are responsible for implementing the only method within Runnable&#151;the <B>run()</B> method.</P>
<P>A Java Object should implement the Runnable interface if it is intended to execute code. If a Java Object implements Runnable, the Java Virtual Machine (VM) will eventually call the <B>run()</B> function, which that object implements.</P>
<P>The Java Thread class implements Runnable. This is logical because the only purpose of a Thread is to execute some sequence of code, either once or repeatedly.</P>
<H4 ALIGN="LEFT"><A NAME="Heading4"></A><FONT COLOR="#000077">What is Provided by Runnable?</FONT></H4>
<P>Runnable provides the means for a class to be active while not subclassing Thread. A class that implements Runnable can run without subclassing Thread by instantiating a Thread instance and passing itself in as the target. This was referred to as &#147;Method 2&#148; in Lesson 2.
</P>
<P><FONT SIZE="+1"><B>Refresher</B></FONT></P>
<P>As a refresher, below is an example of what is being discussed:
</P>

<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD>
<!-- CODE //-->
<PRE>
public class foo implements Runnable

 {

    ...

    public void run()

   {

       Thread t = new Thread(this);

   }
}
</PRE>
<!-- END CODE //-->
</TD>
</TR>
</TABLE>

<H4 ALIGN="LEFT"><A NAME="Heading5"></A><FONT COLOR="#000077">The Run Method</FONT></H4>
<P>The declaration of the <B>run()</B> method is as follows:</P>

<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD>
<!-- CODE SNIP //-->
<PRE>
public abstract void run()
</PRE>
<!-- END CODE SNIP //-->
</TD>
</TR>
</TABLE>

<P>This is the method that is executed when a Runnable object is activated. The <B>run()</B> method is the &#147;soul&#148; of a Thread. It is in this method that all of the action of a Thread takes place.</P>
<TABLE WIDTH="100%"><TR>
<TD VALIGN="TOP" ALIGN="LEFT" WIDTH="5%"><IMG SRC="images/03-01i.jpg"></TD>
<TD VALIGN="TOP" ALIGN="LEFT">The <B>run()</B> method is the &#147;soul&#148; of a Thread. It is in this method that all of the action of a Thread takes place.</TD>
</TR>
</TABLE>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch02/02-01.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch04/04-01.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>

<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright &copy; <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>&nbsp;|&nbsp;<a href="/contactus.html"><font color="#0099CC">Contact Us</font></a>&nbsp;|&nbsp;<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>&nbsp;|&nbsp;<a href="http://www.earthweb.com/dlink.corp|privacy-jhtml.72.0.-.-.jhtml" target="resource window"><font color="#0099CC">Privacy</font></a>&nbsp;|&nbsp;<a href="http://www.itmarketer.com/" target="resource window"><font color="#0099CC">Ad Info</font></a>&nbsp;|&nbsp;<!--<a href="/consortia/"><font color="#0099CC">Consortia</font></a>&nbsp;|&nbsp;--><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 &amp; Conditions</font></a>, <a href="/copyright.html"><font color="#0099CC">Copyright &copy; 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 + -