?? 輕松使用線程:不共享有時是最好的.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0068)http://www-900.ibm.com/developerWorks/cn/java/j-threads/index3.shtml -->
<HTML><HEAD><TITLE>輕松使用線程:不共享有時是最好的</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META scheme=iso8601 content=2002-06-04 name=DC.DATE>
<META content="developerWorks 中國網站" name=TITLE>
<META content=papers_html name=dWCategory>
<META content=Java name=zone><!-- Java technology-->
<META
content="synchronization, performance, multithreaded, Java threads, contention, Java programming, ThreadLocal, concurrent programming, Brian Goetz, 同步, 性能, 多線程的, Java 線程, 爭用, Java 編程, 并發編程"
name=keywords>
<META
content="ThreadLocal 類是悄悄地出現在 Java 平臺版本 1.2 中的。雖然 ThreadLocal 極少受到關注,但對簡化線程安全并發程序的開發來說,它卻是很方便的。在輕松使用線程的第 3 部分中,Java 軟件顧問 Brian Goetz 研究了 ThreadLocal 并提供了一些使用技巧。"
name=ABSTRACT>
<META
content="ThreadLocal 類是悄悄地出現在 Java 平臺版本 1.2 中的。雖然 ThreadLocal 極少受到關注,但對簡化線程安全并發程序的開發來說,它卻是很方便的。在輕松使用線程的第 3 部分中,Java 軟件顧問 Brian Goetz 研究了 ThreadLocal 并提供了一些使用技巧。"
name=DESCRIPTION>
<SCRIPT language=JavaScript type=text/javascript>var forumURL = "http://www-105.ibm.com/developerWorks/java_df.nsf/AllViewTemplate?OpenForm&RestrictToCategory=23"; </SCRIPT>
<SCRIPT language=JavaScript src="輕松使用線程:不共享有時是最好的.files/forumwindow.js"
type=text/javascript></SCRIPT>
<META content=/developerWorks/cn/cncontent.nsf/cn_dW_feedback name=OWNER>
<META content="2001**** initials" name=LASTUPDATE>
<META content=Public name=SECURITY>
<META content=text/xhtml name=FORMAT>
<META content="Copyright (c) 2000 by IBM Corporation" name=COPYRIGHT>
<META content=index,follow name=ROBOTS>
<META content=cn name=IBM.COUNTRY>
<META name=DOCUMENTCOUNTRYCODE value="us">
<META name=DOCUMENTLANGUAGECODE value="en">
<META http-equiv=PICS-Label
content='(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" by "webmaster@mail.software.ibm.com" for "http://www.ibm.com/software" on "1997.08.13T17:59-0800" r (n 0 s 0 v 0 l 0))'>
<META http-equiv=Expires content=0>
<SCRIPT language=JavaScript src="輕松使用線程:不共享有時是最好的.files/style.js"
type=text/javascript></SCRIPT>
<SCRIPT language=JavaScript src="輕松使用線程:不共享有時是最好的.files/spinbox.js"
type=text/javascript></SCRIPT>
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=2 topMargin=2 marginwidth="2" marginheight="2"><!-- MASTHEAD-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=tbgc width=160><A
href="http://www-900.ibm.com/developerWorks/cn/cgi-bin/click.cgi?url=www.ibm.com/cn/&origin=dwheader"><IMG
height=47 alt=IBM src="輕松使用線程:不共享有時是最好的.files/ibm-logo.gif" width=160
border=0></A></TD>
<TD class=tbg width=70><FONT color=#99ccff size=2><B>China</B></FONT><A
href="http://www-900.ibm.com/developerWorks/cn/java/j-threads/index3.shtml#main"><IMG
height=1 alt="Skip to main content" src="輕松使用線程:不共享有時是最好的.files/c.gif"
width=70 border=0></A></TD>
<TD class=tbgc vAlign=top align=right width="100%">
<TABLE cellSpacing=0 cellPadding=0 border=0>
<FORM id=form1 name=form1
action=http://www-106.ibm.com/search/searchResults.jsp method=get>
<TBODY>
<TR>
<TD colSpan=7><IMG height=4 alt=""
src="輕松使用線程:不共享有時是最好的.files/c.gif" width=390 border=0></TD></TR>
<TR vAlign=center>
<TD class=dwsearch><NOBR><FONT
color=#ffffff><B>搜索:</B></FONT></NOBR> </TD>
<TD><INPUT class=dwsearch maxLength=100 size=23 name=query></TD>
<TD class=dwsearch vAlign=center> <FONT
color=#ffffff><B>在</B></FONT> </TD>
<TD class=dwsearch><SELECT class=dwsearch2
name=searchScope> <OPTION value=dW selected>dW
全部內容</OPTION> <OPTION value=javaZ> Java 技術</OPTION> <OPTION
value=linuxZ> Linux</OPTION> <OPTION
value=opensrcZ> 開放源碼</OPTION> <OPTION
value=securityZ> 安全</OPTION> <OPTION value=webservZ> Web
服務</OPTION> <OPTION value=xmlZ> XML</OPTION> <OPTION
value=dW>.................</OPTION> <OPTION
value=dmdd> DB2</OPTION> <OPTION
value=wsdd> WebSphere</OPTION> <OPTION
value=lotusdd> Lotus 專題</OPTION> <OPTION
value=tivolidd> Tivoli 專題</OPTION> <OPTION
value=dW>.................</OPTION> <OPTION value=all>IBM
全部內容</OPTION></SELECT></TD>
<TD><IMG height=1 alt="" src="輕松使用線程:不共享有時是最好的.files/c.gif" width=5
border=0></TD>
<TD><INPUT type=image height=23 alt="Search button" width=64
src="輕松使用線程:不共享有時是最好的.files/search.gif" value=Search border=0
name=Search></TD>
<TD vAlign=top><IMG height=1 alt=""
src="輕松使用線程:不共享有時是最好的.files/c.gif" width=30 border=0></TD></TR>
<TR vAlign=top>
<TD> </TD>
<TD class=dwsearch> <FONT color=#ffffff>只用 + - " "
( )</FONT>
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD> </TD></TR><INPUT type=hidden value=1 name=searchType> <INPUT
type=hidden value=dWChina name=searchSite> <INPUT type=hidden value=zh
name=pageLang> <INPUT type=hidden value=gb2312 name=langEncoding>
</FORM></TBODY></TABLE></TD></TR><A id=main name=main>
<TR>
<TD class=hbg width=160 height=21> </TD>
<TD class=bbg vAlign=top colSpan=2 height=21> <A
class=mainlink
href="http://www-900.ibm.com/developerWorks/cn/cgi-bin/click.cgi?url=www-900.ibm.com/cn/&origin=dwhead">IBM
主頁</A> <SPAN class=divider> | </SPAN> <A
class=mainlink
href="http://www-900.ibm.com/developerWorks/cn/cgi-bin/click.cgi?url=www-900.ibm.com/cn/products/index.shtml&origin=dwhead">產品與服務</A>
<SPAN class=divider> | </SPAN> <A class=mainlink
href="http://www-900.ibm.com/developerWorks/cn/cgi-bin/click.cgi?url=www-900.ibm.com/cn/support/index.shtml&origin=dwhead">支持與下載</A>
<SPAN class=divider> | </SPAN> <A class=mainlink
href="http://www-900.ibm.com/developerWorks/cn/cgi-bin/click.cgi?url=www-900.ibm.com/cn/account/index.shtml&origin=dwhead">個性化服務</A></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR class=hil>
<TD width="100%" height=1><IMG height=1 alt=""
src="輕松使用線程:不共享有時是最好的.files/c.gif" width=592></TD></TR>
<TR class=dwr1>
<TD width="100%" height=2><IMG height=2 alt=""
src="輕松使用線程:不共享有時是最好的.files/c.gif" width=592></TD></TR>
<TR class=dwg3>
<TD width="100%" height=1><IMG height=1 alt=""
src="輕松使用線程:不共享有時是最好的.files/c.gif" width=592></TD></TR>
<TR class=bbg>
<TD width="100%" height=1><IMG height=1 alt=""
src="輕松使用線程:不共享有時是最好的.files/c.gif" width=592></TD></TR>
<TR class=hil>
<TD width="100%" height=1><IMG height=1 alt=""
src="輕松使用線程:不共享有時是最好的.files/c.gif" width=592></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR vAlign=top>
<TD width=5><IMG height=1 alt="" src="輕松使用線程:不共享有時是最好的.files/c.gif"
width=5 border=0></TD>
<TD width="100%">
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR vAlign=top>
<TD width="100%"><IMG height=4 alt=""
src="輕松使用線程:不共享有時是最好的.files/c.gif" width=2 border=0><BR><B><A
href="http://www-900.ibm.com/developerWorks/cn/index.shtml">developerWorks
中國網站</A> : <A
href="http://www-900.ibm.com/developerWorks/cn/java/index.shtml">Java</A>
: <A
href="http://www-900.ibm.com/developerWorks/cn/cnpapers.nsf/java-papers-bynewest?OpenView&count=10">所有的文章
</A></B></TD>
<TD align=right width=136><A
href="http://www-900.ibm.com/developerWorks/cn/index.shtml"><IMG
height=24 alt="developerWorks 中國網站"
src="輕松使用線程:不共享有時是最好的.files/dwlogo-small.gif" width=136
border=0></A></TD>
<TD width=5><IMG height=1 alt="" src="輕松使用線程:不共享有時是最好的.files/c.gif"
width=5 border=0></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><!-- Title Area-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR vAlign=top>
<TD colSpan=5><IMG height=15 alt="" src="輕松使用線程:不共享有時是最好的.files/c.gif"
width=5 border=0></TD></TR>
<TR vAlign=top>
<TD width=2><IMG height=1 alt="" src="輕松使用線程:不共享有時是最好的.files/c.gif"
width=2 border=0></TD>
<TD><SPAN class=astitle>輕松使用線程:</SPAN> <SPAN
class=atitle>不共享有時是最好的</SPAN></TD>
<TD width=8><IMG height=1 alt="" src="輕松使用線程:不共享有時是最好的.files/c.gif"
width=8 border=0></TD>
<TD vAlign=bottom align=right width=180><NOBR><A
href="http://www-900.ibm.com/developerWorks/cn/java/j-threads/index3_eng.shtml"
target=_blank><B>英文原文</B></A></NOBR></TD>
<TD width=6><IMG height=1 alt="" src="輕松使用線程:不共享有時是最好的.files/c.gif"
width=6 border=0></TD></TR><!-- Black line separator-->
<TR vAlign=top>
<TD bgColor=#000000 colSpan=5><IMG height=1 alt=""
src="輕松使用線程:不共享有時是最好的.files/c.gif" width=100 border=0></TD></TR>
<TR vAlign=top>
<TD bgColor=#ffffff colSpan=5><IMG height=8 alt=""
src="輕松使用線程:不共享有時是最好的.files/c.gif" width=100 border=0></TD></TR></TBODY></TABLE><!-- END HEADER AREA--><!-- START BODY AREA-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR vAlign=top>
<TD width=10><IMG height=1 alt="" src="輕松使用線程:不共享有時是最好的.files/c.gif"
width=10 border=0></TD>
<TD width="100%">
<TABLE cellSpacing=0 cellPadding=0 width=168 align=right border=0>
<TBODY>
<TR><!-- Sidebar Gutter-->
<TD width=8><IMG height=21 alt="" src="輕松使用線程:不共享有時是最好的.files/c.gif"
width=5></TD>
<TD width=160><!-- Start TOC-->
<TABLE cellSpacing=0 cellPadding=0 width=160 border=0>
<TBODY>
<TR>
<TD width=160 bgColor=#000000 height=1><IMG height=1 alt=""
src="輕松使用線程:不共享有時是最好的.files/c.gif" width=160></TD></TR>
<TR>
<TD align=middle background=輕松使用線程:不共享有時是最好的.files/bg-gold.gif
height=5><B>內容:</B></TD></TR>
<TR>
<TD width=160 bgColor=#666666 height=1><IMG height=1 alt=""
src="輕松使用線程:不共享有時是最好的.files/c.gif" width=160></TD></TR>
<TR>
<TD align=right>
<TABLE cellSpacing=0 cellPadding=3 width="98%" border=0>
<TBODY>
<TR>
<TD><A
href="http://www-900.ibm.com/developerWorks/cn/java/j-threads/index3.shtml#h5450">什么是線程局部變量(thread-local
variable)?</A></TD></TR>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -