📄 轻松使用线程:不共享有时是最好的.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 + -