?? 04-02.html
字號:
<option value="/reference/dir.2-certification.html">Certification & Training <option value="/reference/dir.3-databaseanderp.html">Database & 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 & OS <option value="/reference/dir.8-ibmredbooks.html">IBM RedBooks <option value="/reference/dir.9-networktelcom.html">Network & Telecom <option value="/reference/dir.10-websoftwaredev.html">Web & 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> 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="04-01.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch05/05-01.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B>Daemon</B></FONT></P>
<TABLE WIDTH="100%" BORDER>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP" WIDTH="30%"><B>isDaemon()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH="70%">Returns the daemon flag of the Thread.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>setDaemon(boolean)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Marks this Thread as a 1) daemon Thread or 2) user Thread.</TD>
</TR>
</TABLE>
<P><FONT SIZE="+1"><B>Synchronization Methods</B></FONT></P>
<TABLE WIDTH="100%" BORDER>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP" WIDTH="30%"><B>join(long)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH="70%">Waits for this Thread to die.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>join(long, int)</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Waits for the Thread to die, with more precise time.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>join()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Waits forever for this Thread to die.</TD>
</TR>
</TABLE>
<P><FONT SIZE="+1"><B>Other Methods</B></FONT></P>
<TABLE WIDTH="100%" BORDER>
<TR>
<CAPTION VALIGN="BOTTOM"><B>Table 4-4: Additional thread methods</B></CAPTION>
</TR>
<TR>
<TH ALIGN="CENTER" VALIGN="TOP" WIDTH="30%">Method</TH>
<TH ALIGN="CENTER" VALIGN="TOP" WIDTH="30%">Description</TH>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>activeCount()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Returns the current number of active Threads in this Thread group.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>checkAccess()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Checks whether the current Thread is allowed to modify this Thread.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>currentThread()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Returns a reference to the currently executing Thread object.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>dumpStack()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">A debugging procedure to print a stack trace for the current Thread.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>enumerate(Thread[])</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Copies, into the specified array, references to every active Thread in this Thread’s group.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>interrupt()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Send an interrupt to a Thread.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>interrupted()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Asks if you have been interrupted.</TD>
</TR>
<TR>
<TD ALIGN="CENTER" VALIGN="TOP"><B>isInterrupted()</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">Asks if another Thread has been interrupted.</TD>
</TR>
</TABLE>
<H3><A NAME="Heading4"></A><FONT COLOR="#000077">Behind the Scenes: The Thread Class in C</FONT></H3>
<P>As a Web programmer, you should be interested in learning how threads are actually implemented in the Java VM. Experimentation by programmers has revealed much. The Sun JDK also contains some files which provide information regarding the underlying implementation of Java.
</P>
<P>Below is the underlying C structure that corresponds to the Thread class. This can be found in: THREADS/INCLUDE/JAVA_LANG_THREAD.H.</P>
<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD>
<!-- CODE //-->
<PRE>
typedef struct Classjava_lang_Thread
{
struct HArrayOfChar *name;
long priority;
struct Hjava_lang_Thread *threadQ;
long PrivateInfo;
long eetop;
/*boolean*/ long single_step;
/*boolean*/ long daemon;
/*boolean*/ long stillborn;
struct Hjava_lang_Runnable *target;
struct Hjava_lang_ThreadGroup *group;
long initial_stack_memory;
} Classjava_lang_Thread;
</PRE>
<!-- END CODE //-->
</TD>
</TR>
</TABLE>
<P>Note the following regarding the internal representation of Threads within the Java VM:
</P>
<DL>
<DD><B>•</B> <U>Each thread has a name and a priority</U>: there appears to be a pointer to a queue; this is possibly the queue on which Java keeps all Not Runnable threads. The variable <B>eetop</B> may be a pointer to the top of this thread’s stack area and the size of the stack space.
<DD><B>•</B> <U>There are some boolean variables which relate to the thread’s state</U>: there is a pointer to the thread’s Runnable object (some Thread constructors take a Runnable as an argument). Also, there is a pointer to the ThreadGroup to which the thread belongs.
<DD><B>•</B> <U>The mystery is the <B>PrivateInfo</B> field</U>: this may be used by each vendor that implements a Java VM and may contain operating-system dependent information (for example, it may contain the handle of an actual Win32 thread object).
</DL>
<P><B>Lab 2: Displaying Stock Information</B></P>
<P>Remember the stock files you generated in the first Lab exercise?</P>
<P>In this Lab, you will read them back in and display them in <B><I>n</I></B> different listboxes. Perform the following steps:</P>
<DL>
<DD><B>1.</B> Avoid hard-coding constant array sizes in this application. Therefore, one task that you must perform is to determine how many STK files are available in Java. (Hint: examine the Java <B>File</B> class).
<DD><B>2.</B> For each stock file, create a new Stock object that contains information regarding that stock. Read in the price information using <U>one thread per stock file</U>.
<DD><B>3.</B> Dynamically create a listbox for each stock file and fill each listbox with the prices for that stock. Use <U>one thread per listbox</U> into which you are going to insert data.
<DD><B>4.</B> Make this application an Applet. It has a user interface component (the three listboxes), and uses the Java AWT classes. Thus, a console application will not work here; you need to make this into an Applet.
</DL>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="04-01.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch05/05-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 © <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 + -