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

📄 关于threadlocal用法的一点疑惑1.mht

📁 hibernate(java 相关)书籍
💻 MHT
📖 第 1 页 / 共 5 页
字号:
bold">=B5=AB=CA=C7=CD=F8=C9=CF=BA=C3=D0=A9=C0=FD=D7=D3=B6=BC=BD=ABThreadL=
ocalSession.closeSession();=B7=C5=D4=DAmethod=D6=D0=A3=AC</SPAN>=CE=D2=BE=
=F5=B5=C3=C4=C7=D1=F9=B5=C4=BB=B0=A3=ACThreadLocal=C6=F1=B2=BB=CA=C7=C3=BB=
=D3=D0=C8=CE=BA=CE=D7=F7=D3=C3=A3=BF=20
                  =
<BR>=D5=D5=D1=F9=D4=DA=D2=BB=B8=F6=CF=DF=B3=CC=D6=D0open,close =
session=B6=E0=B4=CE=A3=BF=B5=AB=CA=C7=A3=AC=D3=C9=D3=DA=BC=FB=B5=BD=B5=C4=
=D5=E2=D1=F9=B5=C4=B4=FA=C2=EB=20
                  =
<BR>=BA=C3=BC=B8=B4=CE=A3=AC=CB=F9=D2=D4=C0=B4=D5=E2=C0=EF=C8=B7=C8=CF=D2=
=BB=CF=C2=A1=A3 =
<BR><BR>btw=A3=BA=D5=E2=B6=CEGavinKing=B5=C4=BB=B0=A3=AC=B2=BB=CA=C7=CC=AB=
=C3=F7=B0=D7=A3=AC=B0=EF=C3=A6=BD=E2=CA=CD=D2=BB=CF=C2=A3=BA=20
                  <BR>Thread Local Session <BR>Hibernate is designed to =
be=20
                  useable in any kind of Java application, including=20
                  applications that make extensive use of =
multithreading. So,=20
                  unlike the ODMG API, Hibernate's native API does not =
use the=20
                  current thread to maintain associations between =
Session and=20
                  Transaction or between Session and application thread. =
This=20
                  can be inconvenient for J2EE applications where access =
to a=20
                  Session instance is always from a particular thread. =
It is=20
                  particularly inconvenient when using a DAO pattern, =
when the=20
                  different DAO classes need to obtain the (same) =
current=20
                  session</SPAN><SPAN class=3Dpostbody></SPAN><SPAN=20
                  =
class=3Dgensmall></SPAN></TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD class=3Drow1 vAlign=3Dcenter align=3Dleft =
width=3D150><SPAN class=3Dnav><A=20
            class=3Dnav=20
            =
href=3D"http://forum.javaeye.com/viewtopic.php?t=3D1732&amp;postdays=3D0&=
amp;postorder=3Dasc&amp;start=3D0&amp;sid=3Dd06314db12f3d4fc205656e20ec0b=
897#top">=B7=B5=BB=D8=B6=A5=B6=CB</A></SPAN></TD>
          <TD class=3Drow1 vAlign=3Dbottom noWrap width=3D"100%" =
height=3D28>
            <TABLE height=3D18 cellSpacing=3D0 cellPadding=3D0 =
width=3D18 border=3D0>
              <TBODY>
              <TR>
                <TD vAlign=3Dcenter noWrap><A=20
                  =
href=3D"http://forum.javaeye.com/profile.php?mode=3Dviewprofile&amp;u=3D1=
365"><IMG=20
                  title=3D=D4=C4=B6=C1=BB=E1=D4=B1=D7=CA=C1=CF =
alt=3D=D4=C4=B6=C1=BB=E1=D4=B1=D7=CA=C1=CF=20
                  =
src=3D"http://forum.javaeye.com/templates/subSilver/images/lang_chinese_s=
implified/icon_profile.gif"=20
                  border=3D0></A> <A=20
                  =
href=3D"http://forum.javaeye.com/privmsg.php?mode=3Dpost&amp;u=3D1365"><I=
MG=20
                  title=3D=B7=A2=CB=CD=D5=BE=C4=DA=B6=CC=D0=C5 =
alt=3D=B7=A2=CB=CD=D5=BE=C4=DA=B6=CC=D0=C5=20
                  =
src=3D"http://forum.javaeye.com/templates/subSilver/images/lang_chinese_s=
implified/icon_pm.gif"=20
                  border=3D0></A> </TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD class=3DspaceRow colSpan=3D2 height=3D1><IMG height=3D1 =
alt=3D""=20
            =
src=3D"http://forum.javaeye.com/templates/subSilver/images/spacer.gif"=20
            width=3D1></TD></TR>
        <TR>
          <TD class=3Drow2 vAlign=3Dtop align=3Dleft width=3D150><SPAN =
class=3Dname><A=20
            name=3D8034></A><B>robbin</B></SPAN><BR><SPAN=20
            =
class=3Dpostdetails><STRONG></STRONG>=C2=DB=CC=B3=B9=DC=C0=ED=D4=B1<BR><I=
MG title=3D=C2=DB=CC=B3=B9=DC=C0=ED=D4=B1=20
            alt=3D=C2=DB=CC=B3=B9=DC=C0=ED=D4=B1 =
src=3D"http://forum.javaeye.com/images/rank/rank_dev.gif"=20
            border=3D0><BR><IMG alt=3D""=20
            =
src=3D"http://forum.javaeye.com/images/avatars/16324666244056d2fa09632.jp=
g"=20
            border=3D0><BR><BR>=D0=D4=B1=F0:<IMG =
title=3D=D0=D4=B1=F0:=C4=D0 alt=3D=D0=D4=B1=F0:=C4=D0=20
            =
src=3D"http://forum.javaeye.com/templates/subSilver/images/icon_minigende=
r_male.gif"=20
            border=3D0><BR>=C4=EA=C1=E4:29 =
<BR>=CA=AE=B6=FE=B9=AC=CD=BC:<IMG title=3D=B0=D7=D1=F2=B9=AC =
alt=3D=B0=D7=D1=F2=B9=AC=20
            =
src=3D"http://forum.javaeye.com/templates/subSilver/images/icon_mini_arie=
s.gif"=20
            border=3D0><BR>=BC=D3=C8=EB=CA=B1=BC=E4: =
2003/09/07<BR>=CE=C4=D5=C2: 1830<BR>=C0=B4=D7=D4: =C9=CF=BA=A3<BR><IMG =
title=3D=C0=EB=CF=DF=20
            alt=3D=C0=EB=CF=DF=20
            =
src=3D"http://forum.javaeye.com/templates/subSilver/images/offline.gif"=20
            border=3D0></SPAN><BR></TD>
          <TD class=3Drow2 vAlign=3Dtop width=3D"100%" height=3D28>
            <TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"100%" =
border=3D0>
              <TBODY>
              <TR>
                <TD width=3D"100%"><A=20
                  =
href=3D"http://forum.javaeye.com/viewtopic.php?p=3D8034#8034"><IMG=20
                  title=3D=CE=C4=D5=C2 height=3D9 alt=3D=CE=C4=D5=C2=20
                  =
src=3D"http://forum.javaeye.com/templates/subSilver/images/icon_minipost.=
gif"=20
                  width=3D12 border=3D0></A><SPAN =
class=3Dpostdetails>=CA=B1=BC=E4: 2003-12-03=20
                  14:08:44<SPAN class=3Dgen>&nbsp;</SPAN>&nbsp; =
&nbsp;=B1=EA=CC=E2:=20
                </SPAN></TD>
                <TD vAlign=3Dtop noWrap><A=20
                  =
href=3D"http://forum.javaeye.com/posting.php?mode=3Dquote&amp;p=3D8034"><=
IMG=20
                  title=3D=D2=FD=D3=C3=BB=D8=B8=B4 =
alt=3D=D2=FD=D3=C3=BB=D8=B8=B4=20
                  =
src=3D"http://forum.javaeye.com/templates/subSilver/images/lang_chinese_s=
implified/icon_quote.gif"=20
                  border=3D0></A> <A=20
                  =
href=3D"http://forum.javaeye.com/addblog.php?type=3Djavaeye&amp;title=3D=CC=
=D6=C2=DB=A3=BA=B9=D8=D3=DAThreadLocal=D3=C3=B7=A8=B5=C4=D2=BB=B5=E3=D2=C9=
=BB=F3&amp;t=3D1732&amp;postdays=3D0&amp;postorder=3Dasc&amp;start=3D0&am=
p;p=3D8034"><IMG=20
                  =
title=3D=BD=AB=D5=E2=B8=F6=CC=FB=D7=D3=BC=D3=C8=EB=CE=D2=B5=C4Blog =
alt=3D=BD=AB=D5=E2=B8=F6=CC=FB=D7=D3=BC=D3=C8=EB=CE=D2=B5=C4Blog=20
                  =
src=3D"http://forum.javaeye.com/templates/subSilver/images/icon_blog.gif"=
=20
                  border=3D0></A></TD></TR>
              <TR>
                <TD colSpan=3D2>
                  <HR>
                </TD></TR>
              <TR>
                <TD colSpan=3D2><SPAN class=3Dpostbody></SPAN>
                  <TABLE cellSpacing=3D1 cellPadding=3D3 width=3D"90%" =
align=3Dcenter=20
                  border=3D0>
                    <TBODY>
                    <TR>
                      <TD><SPAN =
class=3Dgenmed><B>=D2=FD=D3=C3:</B></SPAN></TD></TR>
                    <TR>
                      <TD=20
                        =
class=3Dquote>=B5=AB=CA=C7=CD=F8=C9=CF=BA=C3=D0=A9=C0=FD=D7=D3=B6=BC=BD=AB=
ThreadLocalSession.closeSession();=B7=C5=D4=DAmethod=D6=D0</TD></TR></TBO=
DY></TABLE><SPAN=20
                  =
class=3Dpostbody><BR><BR>=C8=E7=B9=FB=D4=DAWeb=D3=A6=D3=C3=D6=D0=A3=AC=D3=
=A6=B8=C3=B7=C5=D4=DAServletFilter=C0=EF=C3=E6=CD=AC=D2=BBcloseSession=B5=
=C4=A1=A3=C8=E7=B9=FB=D4=DA=D2=B3=C3=E6=C0=EF=C3=E6=BE=CDcloseSession=A3=AC=
=C4=C7=C3=B4=BF=CF=B6=A8=BE=CD=C3=BB=D3=D0=B7=A2=BB=D3ThreadLocal=B5=C4=D0=
=A7=B9=FB=A1=A3=20
                  =
<BR><BR>=CE=D2=CF=D6=D4=DA=D0=B4=B5=C4=B3=CC=D0=F2=B2=BB=CA=C7Web=B3=CC=D0=
=F2=A3=AC=CE=D2=D2=B2=D4=DA=B3=CC=D0=F2=C0=EF=C3=E6=B2=BB=B9=D8=B1=D5Sess=
ion=B5=C4=A3=AC=B6=F8=CA=C7=D7=EE=BA=F3=CD=B3=D2=BB=B9=D8=B1=D5=A1=A3=20
                  <BR><BR>=C0=FD=C8=E7=A3=BA <BR><BR></SPAN>
                  <TABLE cellSpacing=3D1 cellPadding=3D3 width=3D"90%" =
align=3Dcenter=20
                  border=3D0>
                    <TBODY>
                    <TR>
                      <TD><SPAN =
class=3Dgenmed><B>java=B4=FA=C2=EB:&nbsp;</B></SPAN></TD></TR>
                    <TR>
                      <TD class=3Dcode>
                        <DIV=20
                        style=3D"FONT-FAMILY: 'Courier New', Courier, =
monospace"><BR>&nbsp;=20
                        &nbsp; &nbsp; &nbsp; <SPAN=20
                        style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
                        ?>public</SPAN> <SPAN=20
                        style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
                        ?>static</SPAN> <SPAN=20
                        style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
                        ?>boolean</SPAN> updateUser<SPAN=20
                        style=3D"COLOR: #000000">(</SPAN>User user<SPAN=20
                        style=3D"COLOR: #000000">)</SPAN> <SPAN=20
                        style=3D"COLOR: #000000">{</SPAN> <BR>&nbsp; =
&nbsp; &nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <SPAN=20
                        style=3D"FONT-WEIGHT: bold; COLOR: #990066" =
?>try</SPAN>=20
                        <SPAN style=3D"COLOR: #000000">{</SPAN> =
<BR>&nbsp; &nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; Session s =3D ReportSession.<SPAN=20
                        style=3D"COLOR: =
#000000">currentSession</SPAN><SPAN=20
                        style=3D"COLOR: #000000">(</SPAN><SPAN=20
                        style=3D"COLOR: #000000">)</SPAN>; <BR>&nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; ReportSession.<SPAN=20
                        style=3D"COLOR: =
#000000">currentTransaction</SPAN><SPAN=20
                        style=3D"COLOR: #000000">(</SPAN><SPAN=20
                        style=3D"COLOR: #000000">)</SPAN>;&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
s.<SPAN=20
                        style=3D"COLOR: #000000">update</SPAN><SPAN=20
                        style=3D"COLOR: #000000">(</SPAN>user<SPAN=20
                        style=3D"COLOR: #000000">)</SPAN>; <BR>&nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; s.<SPAN=20
                        style=3D"COLOR: #000000">flush</SPAN><SPAN=20
                        style=3D"COLOR: #000000">(</SPAN><SPAN=20
                        style=3D"COLOR: #000000">)</SPAN>;&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <SPAN=20
                        style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
                        ?>return</SPAN> <SPAN=20
                        style=3D"FONT-WEIGHT: bold; COLOR: #990066" =
?>true</SPAN>;=20
                        <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; <SPAN style=3D"COLOR: #000000">}</SPAN> =
<SPAN=20
                        style=3D"FONT-WEIGHT: bold; COLOR: #990066" =
?>catch</SPAN>=20
                        <SPAN style=3D"COLOR: =
#000000">(</SPAN>HibernateException=20
                        e<SPAN style=3D"COLOR: #000000">)</SPAN> <SPAN=20
                        style=3D"COLOR: #000000">{</SPAN> <BR>&nbsp; =
&nbsp; &nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; <SPAN style=3D"COLOR: #aaaadd"=20
                        ?>System</SPAN>.<SPAN=20
                        style=3D"COLOR: #000000">out</SPAN>.<SPAN=20
                        style=3D"COLOR: #000000">println</SPAN><SPAN=20
                        style=3D"COLOR: #000000">(</SPAN>e.<SPAN=20
                        style=3D"COLOR: #000000">getMessage</SPAN><SPAN=20
                        style=3D"COLOR: #000000">(</SPAN><SPAN=20
                        style=3D"COLOR: #000000">)</SPAN><SPAN=20
                        style=3D"COLOR: #000000">)</SPAN>; <BR>&nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; <SPAN=20
                        style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
                        ?>return</SPAN> <SPAN=20
                        style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
                        ?>false</SPAN>; <BR>&nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; &nbsp; <SPAN=20
                        style=3D"COLOR: #000000">}</SPAN>&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; <SPAN=20
                        style=3D"COLOR: =
#000000">}</SPAN></DIV><BR></TD></TR></TBODY></TABLE><SPAN=20
                  class=3Dpostbody>[/quote]</SPAN><SPAN=20
                  class=3Dpostbody></SPAN><SPAN=20
              =
class=3Dgensmall></SPAN></TD></TR></TBODY></TABLE></TD></TR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -