<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-3345672455004235930</atom:id><lastBuildDate>Thu, 24 Oct 2024 21:51:37 +0000</lastBuildDate><category>linux</category><category>Learn</category><category>娱乐</category><category>comic</category><category>实事</category><category>GTK+/GLib</category><category>IT</category><category>许愿</category><category>Web Design</category><category>iPone/ipod touch</category><category>开源</category><category>音乐</category><title>Swinging</title><description>Memory of my life and idea.</description><link>http://swinging-breeze.blogspot.com/</link><managingEditor>noreply@blogger.com (Unknown)</managingEditor><generator>Blogger</generator><openSearch:totalResults>320</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-6532132107632656515</guid><pubDate>Sun, 22 Aug 2010 14:57:00 +0000</pubDate><atom:updated>2010-08-22T07:57:57.075-07:00</atom:updated><title>blog迁移到appspot</title><description>blogger老早就不能访问了，一开始用gmail发邮件的方式写，后来麻烦了用flymemo记。&lt;br&gt;&lt;br&gt;知识还是需要分享才会增长，重操旧业用micoblog在appspot上打了个blog：&lt;a href=&quot;http://mzhoublog.appspot.com/&quot;&gt;http://mzhoublog.appspot.com/&lt;/a&gt;&lt;br&gt;&lt;br&gt;欢迎来踩踩&lt;br&gt; </description><link>http://swinging-breeze.blogspot.com/2010/08/blogappspot.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-6449558413314123395</guid><pubDate>Thu, 15 Jul 2010 16:08:00 +0000</pubDate><atom:updated>2010-07-15T09:08:31.325-07:00</atom:updated><title>10年7月新番推荐之一</title><description>&lt;span style=&quot;font-family:arial, sans-serif;font-size:13px&quot;&gt;&lt;b&gt;妄想学生会&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;div&gt;&lt;span style=&quot;font-family:arial, sans-serif;font-size:13px&quot;&gt;想听h笑话，喜欢yy谈话。那么你不能不看这部新番。这部动画充满了下半身相关的玩笑。&amp;nbsp;&lt;br&gt;&lt;br&gt;&lt;b&gt;学院默示录&amp;nbsp;&lt;/b&gt;&lt;br&gt;生化危机的学院版，这是对这部作品最好的解释。画风很难得，值得一看。&amp;nbsp;&lt;br&gt;  &lt;br&gt;&lt;b&gt;滑头鬼之孙&lt;/b&gt;&amp;nbsp;&lt;br&gt; 等了很久的夏木友人帐第三季，结果等到了这部。虽然不是走和谐路线，不过也听不错，看起来很有感觉。&amp;nbsp;&lt;br&gt;&lt;br&gt;这次新番虽然数量少了，但是质量普遍高了。这是个好趋势，即使还有很多后宫片，但是画质都不错！&lt;/span&gt; &lt;/div&gt; </description><link>http://swinging-breeze.blogspot.com/2010/07/107.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-7561294031695058164</guid><pubDate>Wed, 23 Jun 2010 06:25:00 +0000</pubDate><atom:updated>2010-06-22T23:25:45.566-07:00</atom:updated><title>冒个泡</title><description>现在已经所有的学习心得移动到了&lt;a href=&quot;http://flymemo.com&quot;&gt;flymemo.com&lt;/a&gt;，所以好久没写blog了，冒个泡。&lt;br&gt; </description><link>http://swinging-breeze.blogspot.com/2010/06/blog-post.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-3052961270425771434</guid><pubDate>Sat, 08 May 2010 02:24:00 +0000</pubDate><atom:updated>2010-05-07T19:24:35.629-07:00</atom:updated><title>使用gtkpod让ubuntu 10.04完全支持iphone/itouch的读写</title><description>&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate; color: rgb(0, 0, 0); font-family: 文泉驿微米黑; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 19px; font-size: small;&quot;&gt;现在10.04能默认识别出iphone/itouch，但是rythmbox只是能读取但不能写入文件。我使用gtkpod来实现对iphone/itouch的完全支持，步骤如下：&lt;br&gt; &lt;br&gt;sudo&amp;nbsp;apt-get&amp;nbsp;install&amp;nbsp;gtkpod&amp;nbsp;ifuse&amp;nbsp;libmp4v2-0&lt;br&gt;&lt;br&gt;安装完成后，&lt;br&gt;&lt;br&gt;$&amp;nbsp;sudo&amp;nbsp;mkdir&amp;nbsp;/mnt/ipod&lt;br&gt;$&amp;nbsp;sudo&amp;nbsp;chmod&amp;nbsp;777&amp;nbsp;/mnt/ipod&lt;br&gt;加载iphone到/mnt/ipod&lt;br&gt;$&amp;nbsp;ifuse&amp;nbsp;/mnt/ipod&amp;nbsp;&lt;br&gt;这时gtkpod就会出现iphone的播放列表了。接下来的操作于ituns类似。gtkpod会在弹出iphone时同步信息。&lt;br&gt; &lt;br&gt;注意使用完毕后卸载iphone：&lt;br&gt;$&amp;nbsp;fusermount&amp;nbsp;-u&amp;nbsp;/mnt/ipod&lt;/span&gt;&lt;/span&gt; </description><link>http://swinging-breeze.blogspot.com/2010/05/gtkpodubuntu-1004iphoneitouch.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-5411636136927053665</guid><pubDate>Sat, 17 Apr 2010 08:14:00 +0000</pubDate><atom:updated>2010-04-17T01:14:50.905-07:00</atom:updated><title>[精品]jQuery用jsonp实现有限制的跨域请求</title><description>&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt;jQuery用jsonp实现有限制的跨域请求&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;浏览器一般意义上是禁止跨域请求的，这是从安全方面来考虑的。但是如果我们的业务是分布式的！这就会产生问题，这在云计算之风大起的今天是个重要问题。一下讲的是一种有限制的跨域请求实现。&lt;/div&gt;&lt;div&gt; &lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;jsonp基本原理：&lt;/b&gt;&lt;/div&gt;&lt;div&gt;插入&amp;lt;script&amp;gt;标签：这个script标签的scr是没有跨域限制的，所以我们可以插入这样一个标签如下：&lt;/div&gt;&lt;div&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http:跨域的请求/getList.js&amp;quot;/&amp;gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt; js里面的实际内容则是：&lt;/div&gt;&lt;div&gt;jsonpcallback(&amp;quot;data&amp;quot;);&lt;/div&gt;&lt;div&gt;这样一旦获取了js文件之后，jsonpcallback函数就会执行。而jsoncallback函数的真正实体事先已经定义好了。&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;jQuery实现jsonp：&lt;/div&gt;&lt;div&gt;浏览器端：&lt;/div&gt;&lt;div&gt;$.getJSON(&amp;quot;http:/跨域的请求/getList.js?data=jsondata&amp;amp;jsoncallback=?&amp;quot;,&lt;/div&gt; &lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;function(data){&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$.each(data.items, function(i,item){&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$(&amp;quot;&amp;lt;img/&amp;gt;&amp;quot;).attr(&amp;quot;src&amp;quot;, item.media.m).appendTo(&amp;quot;#images&amp;quot;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if ( i == 3 ) return false;&lt;/div&gt; &lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;});&lt;/div&gt;&lt;div&gt;});&lt;/div&gt;&lt;div&gt;&lt;b&gt;服务器端（Java）：&lt;/b&gt;&lt;/div&gt;&lt;div&gt;@Override&lt;/div&gt;&lt;div&gt;protected void doGet(HttpServletRequest req, HttpServletResponse resp)&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;throws ServletException, IOException {&lt;/div&gt;&lt;div&gt; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;	&lt;/span&gt;String jsonData = getDataAsJson(req.getParameter(&amp;quot;data&amp;quot;));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;	&lt;/span&gt;String output = req.getParameter(&amp;quot;jsoncallback&amp;quot;) + &amp;quot;(&amp;quot; + jsonData + &amp;quot;);&amp;quot;;&lt;/div&gt; &lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;	&lt;/span&gt;resp.setContentType(&amp;quot;text/javascript&amp;quot;);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;	&lt;/span&gt;PrintWriter out = resp.getWriter();&lt;/div&gt; &lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;	&lt;/span&gt;out.println(output);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;	&lt;/span&gt;// prints: jsonp1232617941775({&amp;quot;symbol&amp;quot; : &amp;quot;IBM&amp;quot;, &amp;quot;price&amp;quot; : &amp;quot;91.42&amp;quot;});&lt;/div&gt; &lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;请求url中的jsoncallback=?就是指定了回调函数也就是getJSON的下一个参数，具体是什么名字则是由jQuery自动生成一个不会重复的函数名，例如：jsonp1232617941775&lt;/div&gt; </description><link>http://swinging-breeze.blogspot.com/2010/04/jqueryjsonp.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-2296286798490865900</guid><pubDate>Wed, 07 Apr 2010 14:15:00 +0000</pubDate><atom:updated>2010-04-07T07:16:00.218-07:00</atom:updated><title>[转]Javascript事件 --PPK</title><description>&lt;p&gt;转自：&lt;a href=&quot;http://www.zipeng.info/archives/ppk-on-js-events.html&quot;&gt;http://www.zipeng.info/archives/ppk-on-js-events.html&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;今天我会说一些关于JavaScript事件的事情，我很希望自己能启发大家一些什么，不过大伙都是高手，不管怎么，我还是要说说 JavaScript事件。&lt;br&gt;大约一年前我打算对JavaScript的事件做一些深入的研究，并且我做了一张兼容性的表，大家可以通过下面这里来 访问&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://quirksmode.org/dom/events&quot; target=&quot;_blank&quot;&gt;http://quirksmode.org/dom/events&lt;/a&gt;&lt;/p&gt;&lt;br&gt;那 么今天我会和大家谈论4件事情：&lt;br&gt;&lt;b&gt;首先&lt;/b&gt;会是key事件（按键事件），因为在这里存在很多的困惑，很多是关于他们如何工作的困惑。&lt;br&gt;&lt;b&gt;然 后&lt;/b&gt;我会谈谈change事件，他是我很喜欢的一个事件，不幸的是，它的工作情况有些乱。&lt;br&gt;&lt;b&gt;第三&lt;/b&gt;，我会谈谈委派focus事 件，当然可能你已经知道了。委派的事件通常只会触发在鼠标或者是键盘事件上，但是我找到了一种办法使它也能够使用在focus上面。&lt;br&gt;&lt;b&gt;最后&lt;/b&gt;我 会说说手机上面的事件，相当诡异的东西。。。&lt;p&gt;那么首先就来看看键盘事件吧，键盘事件有三个：keydown，keypress和keyup。大多数 的人都认为自己很清楚他们在会何时触发，而我在这里要告诉你，其实未必就如你所想的那样。&lt;br&gt;我们先来看看定义，、&lt;br&gt;keydown事件：当用 户按下键盘上面的一个键时会触发，用户一直按着这个键他就会持续触发。&lt;br&gt;keypress事件：有一点点的不同，用户按着一个字符键（原文是 character  key）才触发，就是说用户按了一个能在屏幕上输出字符的按键keypress事件才会触发，比如我们往一个textarea里面输入字符。&lt;br&gt;keyup 事件：很简单，当我们释放一个按键时候会触发。&lt;br&gt;举一个例子，这样你能更明白些&lt;br&gt;比方说我按下了一个字母&quot;o&quot;键或是字母&quot;i&quot;键，那么 keydown和keypress就都会触发，而当我按下的是一个特殊的按键比如是shift键，那么kyedown会触发，而keypress不会。&lt;br&gt;keydown 和keypress的这种区别最初是由微软提出的，所有的ie都支持这种区分方式，一年前（08年吧）推出的safari3.1也适用这样的方式，不过这 只是说明了keydown和keypress存在方式的不同。相比较，firefox和opera会同时触发多个事件，因为此时事件既是一个 keydown事件又是一个keypress事件，所以我们应该会同时触发多个事件。这样很好，但是这样却无法解释为什么要同时存在两种事件、而不是一种 （keydown）。所以其实我还是很喜欢微软的这种区分的。&lt;br&gt;好吧，我们再来重温一次概念，keydown会在任何键按下时触 发，keypress只是在字符键按下时触发，以上是在ie和safari下的情况，另外，我目前没有google  chrome，不过他和safari很相近，所以这个应该也适用于chrome浏览器。&lt;/p&gt;&lt;p&gt;OK，让我们来看一些实际问题，通常我们都会写一段 脚本来检测用户按过哪个按钮，然后利用这样的结果做一些有趣的交互应用。&lt;/p&gt;&lt;p&gt;键盘事件拥有两个属性，keyCode和CharCode，他们之 间有一些不一样之处。keyCode表示用户按下键的实际的编码，而charCode是指用户按下字符的编码。&lt;br&gt;因此，当我按下&quot;a键&quot;，我会得到 keyCode 65和字母a的charCode 97（注意是小写的字母哦），而当我按下shift键，我会得到keyCode  16，而我不会得到任何的charCode，因为按shift并没输入任何的字符。就这样，很简单吧~~~&lt;br&gt;我们现在得到两个属性了，两个属性各自 包含了各种的信息，这真是好事~~~&lt;/p&gt;&lt;p&gt;但是接下来我们又遇到问题了，很复杂，无法解释但它就是这样的问题。keyCode属性。在 keyDown事件里面，事件包含了keyCode �  用户按下的按键的物理编码。在Onkeypress里，keyCode包含了字符编码，即表示字符的ASCII码。这样的形式适用于所有的浏览器 � &lt;b&gt;除 了火狐&lt;/b&gt;，它在onkeypress的时候keyCode返回数字0，  别问我为什么，它就这样。然后，火狐在Onkeydown中charCode返回数字0，在  onkeypress里，由charCode返回字符ASCII编码。而这个，只会在Firefox和Safari工作，因为他们是唯一支持 charCode的浏览器。（这一段翻译感谢信息学院的AN同学的纠正）&lt;/p&gt;&lt;p&gt;让我们更进一步看点更实际的东西，如果你想获取用户实际敲击的按 钮，&lt;b&gt;用keyDown事件来获取事件对象，并获取keyCode&lt;/b&gt;，这在所有浏览器都行的通。另一方面，&lt;b&gt;如果你想获取用户输入的字符， 那么就使用keypress来获取，然后获取charCode（火狐和safari）或是keyCode（其他浏览器）&lt;/b&gt;。&lt;/p&gt;&lt;p&gt;然后，我 想有时候你也会有阻止某个按钮默认行为的想法，很常见的是方向键&lt;br&gt;设想你有一个适合于键盘的拖拽菜单，你希望用户用方向键来实现一个拖拽的操作，因 此你就要取消方向键的默认行为（使页面向上或是向下滚动），那么一般来说你就会在keyDown事件里面做这件事，因为如我所说的那样 ----keyDown会在一个按钮被按下时候触发，而keyPress只是在字符键按下时触发，但是很不幸，这样子在opera行不通（当然我得承认我 没有测试最新版的opera，也许现在已经修复了这个问题？待测试）。因此，我今天不会讨论在opera下面阻止方向键的方法，很坦诚的说，我还没有一个 答案。&lt;/p&gt;&lt;p&gt;这就是键盘事件的一些总结，不会很麻烦吧？我说了几种键盘事件，但是你得注意keydown和keypress的差别。&lt;/p&gt;&lt;p&gt;好 了好了，来说说change事件吧。照理论说，change事件应该是很好的一个事件，因为他应该是在表单有变化的时候触发。比如，你想在表单提交时检测 一些用户操作表单的事情，比如是检测和验证用户在各个域的输入。当然也有很多时候我们会动态创建一个表单或是表单域或是选框--这样的表单会和用户之间产 生很复杂的交互，这时候我们就要知道用户什么时候对表单作了修改，从理论上说，change事件是最合适不过的了。&lt;/p&gt;&lt;p&gt;但是通常，我们总是会被 迫去使用focus和blur事件或者是click事件去做检测表单变化的事，而不是用change事件。这是因为change事件不总是能很正常的运行 着。我们分三种情况来讨论&lt;br&gt;1、文本框的变化事件（text field）&lt;br&gt;2、选择框的变化事件（select box）&lt;br&gt;3、复选 框和单选框的变化事件&lt;/p&gt;&lt;p&gt;从文本框开始说吧，假设用户把焦点移动到了文本框上面（或用鼠标或用键盘的方式），之后又移去了焦点，比如说他进入了 下一个文本框的输入。在这样的情况下，change事件不触发，因为没有什么东西改变了---注意，第一个文本框的值并没有改变。但是我们对上述事情稍稍 做一些变化，如果我们说，用户点击了文本框，并输入了一些文本，然后再撤去焦点，这就触发了change事件，很好，他在所有浏览器中都如此工作。&lt;/p&gt;&lt;p&gt;然 而，当我们使用selectbox的时候问题就来了，选择框事件是你可以想到的最古老的浏览器事件，我想大约在95、96年我们在浏览器中就有了 selectbox了，他可能列出了漂亮的链接，并节省了页面的空间。我们已经使用选择框有很长一段时间了，你也可以用鼠标去做一个选择。首先你点击选择 框，它便列出了选项，当你再次单击里面的一个选项时，就触发了change事件。因为浏览器知道：&quot;ok，用户已经改变了选择框里面的值了&quot;。这也是用于 所有的浏览器。&lt;/p&gt;&lt;p&gt;但是，用户还可以用键盘来操作改变选择框（select）的值，这就为我们使用change事件带来了麻烦。首先用户会把焦 点移动到selectBox上面，然后利用方向键来选择他需要的选项。这还不是什么问题，但是这种情况，在IE和opera下面，每当用户按一次方向键 （切换选项），change事件就会触发一次。这明显是很大的一个问题，如果一个选项表有20个选项，那么用户从第一个选项移到最后一个就会触发19次 change事件，这可以说是ie和opera很严重的一个bug。&lt;br&gt;而在firefox和safari里面，他们所做的工作就是，允许用户在选项 之间用上下键来选择，然后会在用户blur这个选择框的时候触发change事件，通俗的说，你告诉浏览器，我已经选择好了，浏览器你可以用change 事件看看我是不是做了改变----像firefox和safari这样的工作方式很好很正确。不过，在IE下面做一些类似于选框导航的工作，当用户用键盘 来操作，使用change事件就很容易产生问题。这就是我们对于change事件的首个大问题。&lt;/p&gt;&lt;p&gt;不幸的事继续发生，当我们在复选和单选框上 面使用change事件，情况会更糟，我以一个复选框为例，基本上他和单选的工作方式一样。当用户点击了复选框&lt;b&gt;（我不仅仅指用鼠标点选）&lt;/b&gt;， 一个点选操作可以通过鼠标或是键盘来达到。总之，这样的一个点击使得复选框的值发生了变化---true or  false。按常理这时候change就发生了，因为用户确确实实的改变了东西，这样的一件事也的的确确会在firefox，safari，opera里 面发生，&lt;b&gt;但是IE不会&lt;/b&gt;。&lt;br&gt;IE到底怎么了？你点击了复选框而什么也没有发生。接下来呢，你用鼠标或是键盘把焦点移出这个复选框移到别 的复选框上面，原来的这个复选框的blur事件就触发了，同时change事件随之触发。这样的情况对于一些整理表格的操作实现来说是很糟糕的，比如通过 复选框来开启表单的隐藏选项，在IE下面你只能在blur一个复选框的时候开启隐藏选项，这样对于用户来说是很困惑的（因为会给用户带来一种滞后的感 觉）。这也是IE下面一个很严重的bug。&lt;/p&gt;&lt;p&gt;你可以看到我在ppt上面给W3C也划了一个叉号，因为据我所知w3c的事件标准只是规定了 blur，根据标准，一个change事件应该在一个表单域改变并被移去焦点时发生。现在我们可以总结一下，change在文本域里面工作的很不错，当我 们用键盘操作select框是它很有意义，而对于单选框和复选框或者是你用鼠标操作select框change事件使用的意义就不太大。&lt;b&gt;（我作为翻 译认为这里ppk出现了口误，把鼠标和键盘操作selectbox的情况说反了，大家要看了欢迎纠正，另外ppk貌似也没有提到用鼠标scroll方式操 作select框的值的方式）&lt;/b&gt;&lt;/p&gt;&lt;p&gt;这就是我们目前遇到的一个问题，而我目前还没有找到一个很好的解决方式。幸运的是，我们可以用 click事件或是focus事件或是blur事件做一些弥补，虽然这不会花费太多的精力，但是我还是期望change事件能变得真正的实用。这样我们可 以比较统一的用一个事件去侦测一个表单里面的变化并做一些有意思的事。目前这还是我们能期待的。&lt;/p&gt;&lt;p&gt;进入我们今天的第三个话题吧，事件委派 （event delegation），我非常确信你（指yahoo的同学们）应该已经知道什么是事件委派，不过其他的人却不知道，我简单的介绍一下。基 本来说，事件委派是减少定义事件处理的一种方式，我们用下拉菜单为例。用传统的方式，我们可能要对这个下拉菜单添加很多的事件处理函数，当你的鼠标停留在 父级菜单上面，1级子菜单弹出，我们在移动鼠标到1级菜单上面，二级菜单又会出来。而当我们使用事件委派时情况就有所不同，事件委派利用了事件的冒泡，当 用户移动鼠标到一个链接（link）上面，触发了链接的mouseover事件，同时通过冒泡mouseover事件冒泡到了链接的上一级元素，直至冒泡 到整个文档上面，这个过程会触发链接（link）上级任何一个含有mouseover事件的元素的mouseover事件，比如会冒泡到li和ul的 mouseover事件，那我们为什么不把处理事件的函数放在链接的上层呢？这样可以节省众多链接的事件处理函数的绑定。&lt;/p&gt;&lt;p&gt;曾经我的一个客户 抱怨他的站点有点慢，尤其是在IE下面，于是我看了源代码，我发现他的下拉菜单有六七十甚至更多的链接，每一个链接绑定了自己的mouseover、 mousedown、mouseout事件，这就使得页面变得缓慢了。&lt;br&gt;因为每一个浏览器都会为单独的事件处理开辟一个单独的内存，更何况是 IE（拥有内存泄露的美名）。于是我告诉我的客户事件委派，然后。。。。（网页快起来了）&lt;/p&gt;&lt;p&gt;那么首先让我们来建立一个下拉菜单&lt;/p&gt;&lt;pre&gt;&amp;lt;ul&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;&amp;lt;a href=&quot;#&quot;&amp;gt;Multimedialize&amp;lt;/a&amp;gt;&lt;br&gt;&amp;lt;ul&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;&amp;lt;a href=&quot;#&quot;&amp;gt;Sound&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;&amp;lt;a href=&quot;#&quot;&amp;gt;Java applets&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br&gt; &amp;lt;/ul&amp;gt;&amp;lt;/li&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;&amp;lt;a href=&quot;#&quot;&amp;gt;Ajaxify&amp;lt;/a&amp;gt;&lt;br&gt;&amp;lt;ul&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;&amp;lt;a href=&quot;#&quot;&amp;gt;Web 2.0&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;&amp;lt;a href=&quot;#&quot;&amp;gt;Web 3.0&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;&amp;lt;a href=&quot;#&quot;&amp;gt;Web 4.0b&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br&gt; &amp;lt;/ul&amp;gt;&amp;lt;/li&amp;gt;&lt;br&gt;&amp;lt;/ul&amp;gt;&lt;br&gt;&lt;/pre&gt;&lt;p&gt;我们首先把我们的mouseover和mouseout事件处理函数绑定到ul上面，这在所有浏览器中都行的通。&lt;/p&gt;&lt;pre&gt;var dropdown = {&lt;br&gt;    init: function (dropdown) {&lt;br&gt;       dropdown.onmouseover = this.mouseOver;&lt;br&gt;       dropdown.onmouseout = this.mouseOut;&lt;br&gt;     }&lt;br&gt;}&lt;br&gt;&lt;/pre&gt;&lt;p&gt;不过如果一个用户不用鼠标，而是想用键盘操作打开这个下拉菜单，我们又该怎么做呢？这个问题有个我们带来了一个重要的主题，设备的独立 性（让网页支持多种设备的操作）。这也是我想向大家解说的，我们做的东西要兼容各种设备。&lt;br&gt;基本的规则是，&lt;b&gt;所有带有&quot;mouse&quot;在名字里面 的事件，只是在你真正使用鼠标的时候工作。&lt;/b&gt;听起来很简单吧，不过这总会被很多人忽视。因此，我们需要用户使用键盘的时候能告诉我们用户何时是鼠标 移入何时又是鼠标移出的事件，那么目前看最合适不过的就是focus和blur事件。因此，如果事件通过鼠标mouseover或是键盘focus冒泡到 上面的元素，冒泡到达ul时我们就执行目标函数展开菜单。当鼠标mouseout或者是键盘blur冒泡上去时，我们就执行关闭菜单的函数。但是问题在 于，&lt;b&gt;这不可行，因为focus和blur事件不会冒泡。&lt;/b&gt;&lt;/p&gt;&lt;p&gt;这就带给我们另一个问题，&lt;b&gt;什么事件支持冒泡？什么事件又不支持 冒泡？&lt;/b&gt;我们先把事件分为两类：一类是设备事件（鼠标或是键盘按键事件），另一类是界面事件。&lt;/p&gt;&lt;p&gt;鼠标和键盘事件是在使用输入设备的时候 触发的，我还在做一个更好的定义，不过基本是这个意思，基本上用户所作的就是点击鼠标按键、点击键盘按键、移动鼠标或其他的一些事，总之是和一个具体的外 接设备相关的，这些事件的例子如，mouseout，mouseover，click，keydown，keypress，顺便说一声click是唯一既 迟滞鼠标触发又支持键盘触发的事件：你用鼠标点击会触发click，用键盘tab移动焦点到目标然后回车也会触发click。click是很少的能够工作 于多种设备下的事件。因此，一个click事件是很安全的。其他的一些设备事件总是只支持某一个设备，最后要说的，就是以上提及的这些事件支持冒泡，直到 document级。&lt;/p&gt;&lt;p&gt;界面事件，在一个常规事件触发时执行，而不关注它是如何被触发的（翻译的有点生涩，欢迎提意见）&lt;br&gt;界面事件的一 个比较好的例子是，表单的submit事件，当一个表单被提交他就会触发，而表单submit事件并不关心用户是用什么方式来提交表单的，可以使用户用鼠 标点击了提交按钮提交表单，可以是用户输入文本按了回车提交表单，只要是提交了表单，submit事件就会触发。这类事件还有很多，又如 onload，onupload，change，focus，blur，对了这里有我们苦苦追寻的focus和blur事件。因为我们希望我们的下拉菜单 能够兼容多种设备。&lt;/p&gt;&lt;p&gt;&lt;b&gt;大体来说，界面事件不支持冒泡，&lt;/b&gt;对我们来说这真是一个不好的消息，因为如果我们想让键盘用户也能用我们的 下拉菜单，我们就要用到focus和blur。但是focus和blur并不能冒泡上ul元素，我们就只能老老实实的把事件处理绑定在每一个li上面了。 当然还有一个不算好消息的好消息，我们可以在事件捕获中得到focus和blur，事件捕获的工作是和事件冒泡相反的，但是它在IE下不被支持。。。不过 我们一会儿会讨论IE。&lt;/p&gt;&lt;p&gt;我们说事件冒泡，我们点击了a元素，a的click执行，然后事件冒泡到了li，之后是ul，之后是 document。事件捕获则是，在我们点击了a之后，事件从document一级级的下来，经过ul、li、然后才到达a并终止捕获。你会觉得冒泡和捕 获这两个东西用哪个都差不多，不过当我向dean Edwards问了这个问题后，他说：&quot;不不不，你应该在大多数情况下去使用事件捕获&quot;。&lt;/p&gt;&lt;p&gt;当 你要捕获一个focus事件，被绑定在目标元素的祖先元素上的事件就会被执行，这个可以在所有浏览器下使用，当然除了IE，因为它不支持事件捕获。因此基 本来说，如果我们把焦点移上a元素上并同时使用事件冒泡，只有a链接的unfocus事件会被触发。但是我们反过来使用事件捕获，那么这个unfocus 事件就会顺着document-&amp;gt;ul-&amp;gt;li的顺序执行下去。&lt;/p&gt;&lt;p&gt;为什么事件捕获和事件冒泡会有差别？我也说不出。这只是我测试 出来的，我开始在opera里面测试，开始我以为他只是opera特有的，但是我在firefox下面也测试，哦？火狐也有这个特性，然后又测试了 safari，呵呵，safari也有同样的表现，最后，我发现它几乎是一个跨浏览器的特性。这样让我觉得事件冒泡和事件捕获具有同样的作用，因为在我之 前的感觉中，事件是否能被捕获并不最重要，但是能否冒泡就不一样了（能否被冒泡意义重大）。不管怎么说，目前的这种状况（应该是说冒泡和捕获的混乱的支持 情况）意义不是很大，但他确实能解决很实际的问题，因为现在我们可以对focus和blur进行事件委派了。&lt;/p&gt;&lt;p&gt;我们要做的很简单，我们给根元 素添加上addEventListener，并给这个函数的最后一个参数设为true，使其工作在捕获阶段。&lt;/p&gt;&lt;pre&gt;var dropdown = {&lt;br&gt;    init: function (dropdown) {&lt;br&gt;        dropdown.onmouseover = this.mouseOver;&lt;br&gt;        dropdown.onmouseout = this.mouseOut;&lt;br&gt;        dropdown.addEventListener(&amp;#39;focus&amp;#39;,this.mouseOver,true);&lt;br&gt;         dropdown.addEventListener(&amp;#39;blur&amp;#39;,this.mouseOut,true);&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;&lt;/pre&gt;&lt;p&gt;这样，一旦下拉菜单有focus事件发生，那么ul上面的事件捕获就会触发，绑定在上面的this.mouseOver函数就会被执 行。别问why，他就是这样工作的。&lt;/p&gt;&lt;p&gt;当然，因为IE不支持事件捕获，我们还要添加一点点东西，做一些修改，IE虽不支持事件捕获但是他有自 己的解决方案，这是IE所特有的。&lt;/p&gt;&lt;pre&gt;var dropdown = {&lt;br&gt;    init: function (dropdown) {&lt;br&gt;        dropdown.onmouseover = this.mouseOver;&lt;br&gt;        dropdown.onmouseout = this.mouseOut;&lt;br&gt;        &lt;b&gt;if (dropdown.addEventListener) {&lt;/b&gt;&lt;br&gt;             dropdown.addEventListener(&amp;#39;focus&amp;#39;,this.mouseOver,true);&lt;br&gt;            dropdown.addEventListener(&amp;#39;blur&amp;#39;,this.mouseOut,true);&lt;br&gt;        &lt;b&gt;}&lt;/b&gt;&lt;br&gt;        &lt;b&gt;dropdown.onfocusin = this.mouseOver;&lt;/b&gt;&lt;br&gt;         &lt;b&gt;dropdown.onfocusout = this.mouseOut;&lt;/b&gt;&lt;br&gt;    }&lt;br&gt;&lt;/pre&gt;&lt;p&gt;IE带有两个类似于focus和blur的事件，但唯一的区别就在于他们支持冒泡，他们是focusin和focusout，我们给原 来的代码添加上两行，dropdown.onfocusin, and  dropdown.onfocusout。这样我们的事件委派就工作在了所有的浏览器中。&lt;/p&gt; </description><link>http://swinging-breeze.blogspot.com/2010/04/javascript-ppk.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-8140157110896009318</guid><pubDate>Fri, 26 Mar 2010 06:39:00 +0000</pubDate><atom:updated>2010-03-25T23:39:21.870-07:00</atom:updated><title>[精品]Spring MVC的深入学习一</title><description>&lt;b&gt;&lt;div&gt;&lt;b&gt;大部分摘录自：&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal; &quot;&gt;&lt;b&gt;&lt;a href=&quot;http://www.ibm.com/developerworks/cn/java/j-lo-spring25-mvc/&quot;&gt;http://www.ibm.com/developerworks/cn/java/j-lo-spring25-mvc/&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt; &lt;div&gt;&lt;b&gt;&lt;br&gt;&lt;/b&gt;&lt;/div&gt;一 SessionAttribute&lt;/b&gt;&lt;div&gt;&lt;br&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Spring 允许我们有选择地指定 ModelMap 中的哪些属性需要转存到 session 中，以便下一个请求属对应的 ModelMap 的属性列表中还能访问到这些属性。这一功能是通过类定义处标注 @SessionAttributes 注解来实现的。&lt;/span&gt;&lt;div&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;使用方法：&lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt; @Controller @RequestMapping(&amp;quot;/bbtForum.do&amp;quot;) @SessionAttributes(&amp;quot;currUser&amp;quot;) //①将ModelMap中属性名为currUser的属性 //放到Session属性列表中，以便这个属性可以跨请求访问 public class BbtForumController { &amp;hellip;     @RequestMapping(params = &amp;quot;method=listBoardTopic&amp;quot;)     public String listBoardTopic(@RequestParam(&amp;quot;id&amp;quot;)int topicId, User user, ModelMap model) {         bbtForumService.getBoardTopics(topicId);         System.out.println(&amp;quot;topicId:&amp;quot; + topicId);         System.out.println(&amp;quot;user:&amp;quot; + user);         model.addAttribute(&amp;quot;currUser&amp;quot;,user); //②向ModelMap中添加一个属性         return &amp;quot;listTopic&amp;quot;;     } }&lt;/pre&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt;&lt;br&gt;&lt;/pre&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small;&quot;&gt;&lt;b&gt;二 ModelAttribute&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;b&gt;&lt;br&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;上面讲述了如何往ModelMap中放置属性以及如何使ModelMap中的属性拥有Session域的作用范围。除了在JSP视图页面中通过传统的方法访问ModelMap中的属性外，Spring提供了一个@ModelAttribute的注解&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;可以将ModelMap中的属性绑定到请求处理方法的入参中&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;，他还可以与jsp标签&amp;lt;form:form modelAttribute=&amp;quot;entity&amp;quot;&amp;gt;&amp;lt;/form:form&amp;gt;一起使用。&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt; &lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 总结它的作用：&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt; &lt;div&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;将多个参数绑定到一个Bean中；&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/li&gt; &lt;li&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;自动将Bean值add到Model中，相当于进行了Model.addAttribute(&amp;quot;key&amp;quot;,bean)；这样可以在jsp中使用EL表达式或是传统的jsp表达式访问bean；&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/li&gt; &lt;li&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;与jsp标签&amp;lt;form:form modelAttribute=&amp;quot;entity&amp;quot;&amp;gt;&amp;lt;/form:form&amp;gt;一起使用，直接将bean的各个域对应到form标签的子标签（如&amp;lt;form:input path=&amp;quot;field&amp;quot;/&amp;gt;，只需要将域的值设置为path值）直接显示在页面上。&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/li&gt; &lt;li&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;verdana, nsimsun, sans-serif&quot; size=&quot;3&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 12px; line-height: 19px;&quot;&gt;在方法之上使用，使方法的返回值被add到Model中，这个方法会被所有此类中的请求方法被调用时使用。所以所有的请求的model中都会有这个Attribute存在。&lt;/span&gt;&lt;/font&gt;&lt;/li&gt; &lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;br&gt; &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;使用方法：&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt; &lt;div&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt; @Controller @RequestMapping(&amp;quot;/bbtForum.do&amp;quot;) @SessionAttributes(&amp;quot;currUser&amp;quot;) //①让ModelMap的currUser属性拥有session级作用域 public class BbtForumController {  @Autowired private BbtForumService bbtForumService;     @RequestMapping(params = &amp;quot;method=listBoardTopic&amp;quot;)     public String listBoardTopic(@RequestParam(&amp;quot;id&amp;quot;)int topicId, User user, ModelMap model) {         bbtForumService.getBoardTopics(topicId);         System.out.println(&amp;quot;topicId:&amp;quot; + topicId);         System.out.println(&amp;quot;user:&amp;quot; + user);         model.addAttribute(&amp;quot;currUser&amp;quot;,user); //②向ModelMap中添加一个属性         return &amp;quot;listTopic&amp;quot;;     }&lt;/pre&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt;    @RequestMapping(params = &amp;quot;method=listAllBoard&amp;quot;)    //③将ModelMap中的 public String listAllBoard(@ModelAttribute(&amp;quot;currUser&amp;quot;) User user) {  //currUser属性绑定到user入参中。         bbtForumService.getAllBoard();         System.out.println(&amp;quot;user:&amp;quot;+user);         return &amp;quot;listBoard&amp;quot;;     } }&lt;/pre&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; white-space: normal; font-size: 12px; &quot;&gt;&lt;p style=&quot;padding-bottom: 8px; padding-top: 5px; margin-top: 0px; margin-bottom: 0px; &quot;&gt; 在 ② 处，我们向 ModelMap 中添加一个名为 currUser 的属性，而 ① 外的注解使这个 currUser 属性拥有了 session 级的作用域。所以，我们可以在 ③ 处通过 @ModelAttribute 注解将 ModelMap 中的 currUser 属性绑定以请求处理方法的 user 入参中。&lt;/p&gt;&lt;p style=&quot;padding-bottom: 8px; padding-top: 5px; margin-top: 0px; margin-bottom: 0px; &quot;&gt; 所以当我们先调用以下 URL 请求： &lt;a href=&quot;http://localhost/bbtForum.do?method=listBoardTopic&amp;amp;id=1&amp;amp;userName=tom&amp;amp;dept.deptId=12&quot;&gt;http://localhost/bbtForum.do?method=listBoardTopic&amp;amp;id=1&amp;amp;userName=tom&amp;amp;dept.deptId=12&lt;/a&gt;&lt;/p&gt; &lt;p style=&quot;padding-bottom: 8px; padding-top: 5px; margin-top: 0px; margin-bottom: 0px; &quot;&gt;以执行listBoardTopic()请求处理方法，然后再访问以下URL： &lt;a href=&quot;http://localhost/sample/bbtForum.do?method=listAllBoard&quot;&gt;http://localhost/sample/bbtForum.do?method=listAllBoard&lt;/a&gt;&lt;/p&gt; &lt;p style=&quot;padding-bottom: 8px; padding-top: 5px; margin-top: 0px; margin-bottom: 0px; &quot;&gt;你将可以看到 listAllBoard() 的 user 入参已经成功绑定到 listBoardTopic() 中注册的 session 级的 currUser 属性上了。&lt;/p&gt;&lt;p style=&quot;padding-bottom: 8px; padding-top: 5px; margin-top: 0px; margin-bottom: 0px; &quot;&gt; &lt;br&gt;&lt;/p&gt;&lt;p style=&quot;padding-bottom: 8px; padding-top: 5px; margin-top: 0px; margin-bottom: 0px; &quot;&gt;在方法级上使用ModelAttribute：&lt;/p&gt;&lt;p style=&quot;padding-bottom: 8px; padding-top: 5px; margin-top: 0px; margin-bottom: 0px; &quot;&gt;&lt;/p&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt; @Controller @RequestMapping(&amp;quot;/bbtForum.do&amp;quot;) public class BbtForumController {      @Autowired     private BbtForumService bbtForumService;      @ModelAttribute(&amp;quot;items&amp;quot;)//&amp;lt;&amp;mdash;&amp;mdash;①向模型对象中添加一个名为items的属性     public List&amp;lt;String&amp;gt; populateItems() {         List&amp;lt;String&amp;gt; lists = new ArrayList&amp;lt;String&amp;gt;();         lists.add(&amp;quot;item1&amp;quot;);         lists.add(&amp;quot;item2&amp;quot;);         return lists;     }      @RequestMapping(params = &amp;quot;method=listAllBoard&amp;quot;)     public String listAllBoard(@ModelAttribute(&amp;quot;currUser&amp;quot;)User user, ModelMap model) {         bbtForumService.getAllBoard();         //&amp;lt;&amp;mdash;&amp;mdash;②在此访问模型中的items属性         System.out.println(&amp;quot;model.items:&amp;quot; + ((List&amp;lt;String&amp;gt;)model.get(&amp;quot;items&amp;quot;)).size());         return &amp;quot;listBoard&amp;quot;;     } }&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small;&quot;&gt;&lt;b&gt;三 注册自己的属性编辑器&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; white-space: normal; font-size: 12px; &quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small;&quot;&gt;&lt;b&gt;&lt;br&gt; &lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;ul&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small;&quot;&gt;注册框架级的自定义属性编辑器&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;div&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt; &amp;lt;bean class=&amp;quot;org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter&amp;quot;&amp;gt;     &amp;lt;property name=&amp;quot;webBindingInitializer&amp;quot;&amp;gt;         &amp;lt;bean class=&amp;quot;com.baobaotao.web.MyBindingInitializer&amp;quot;/&amp;gt;     &amp;lt;/property&amp;gt; &amp;lt;/bean&amp;gt;&lt;/pre&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt;&lt;br&gt;&lt;/pre&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; white-space: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;div&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt; MyBindingInitializer是继承自&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; white-space: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;div style=&quot;display: inline !important; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; display: inline !important; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; white-space: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;div style=&quot;display: inline !important; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; display: inline !important; &quot;&gt; WebBindingInitializer的类，如下：&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; white-space: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;div style=&quot;display: inline !important; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; display: inline !important; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; white-space: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;div style=&quot;display: inline !important; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; display: inline !important; &quot;&gt; &lt;br&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; white-space: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;div style=&quot;display: inline !important; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; display: inline !important; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; white-space: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;div style=&quot;display: inline !important; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; display: inline !important; &quot;&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; white-space: normal; font-size: 12px; &quot;&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt; public class MyBindingInitializer implements WebBindingInitializer {     public void initBinder(WebDataBinder binder, WebRequest request) {         SimpleDateFormat dateFormat = new SimpleDateFormat(&amp;quot;yyyy-MM-dd&amp;quot;);         dateFormat.setLenient(false);         binder.registerCustomEditor(Date.class,              new CustomDateEditor(dateFormat, false));         binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));     } }&lt;/pre&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; line-height: normal; font-size: small; &quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-weight: normal; font-size: 12px; line-height: 19px; &quot;&gt;&lt;font class=&quot;Apple-style-span&quot; face=&quot;arial&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small;&quot;&gt;注册 Controller 级的自定义属性编辑器&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;如果希望某个属性编辑器仅作用于特定的 Controller，可以在 Controller 中定义一个标注 @InitBinder 注解的方法，可以在该方法中向 Controller 了注册若干个属性编辑器，来看下面的代码：&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, nsimsun, sans-serif; font-size: 12px; line-height: 19px; &quot;&gt;&lt;pre class=&quot;displaycode&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; font-family: &amp;#39;Andale Mono&amp;#39;, &amp;#39;Lucida Console&amp;#39;, Monaco, fixed, monospace; font-size: 11px; &quot;&gt; @Controller public class MyFormController {     @InitBinder     public void initBinder(WebDataBinder binder) { //必须有WebDataBinder类型的参数         SimpleDateFormat dateFormat = new SimpleDateFormat(&amp;quot;yyyy-MM-dd&amp;quot;);         dateFormat.setLenient(false);         binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));     }     &amp;hellip; }&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; </description><link>http://swinging-breeze.blogspot.com/2010/03/spring-mvc.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-786321465373810042</guid><pubDate>Fri, 26 Mar 2010 03:42:00 +0000</pubDate><atom:updated>2010-03-25T20:42:38.781-07:00</atom:updated><title>[note]Spring MVC接收数组或List参数</title><description>&lt;table&gt;&lt;tr class=&quot; &quot;&gt;&lt;td class=&quot;netInfoParamName &quot;&gt;客户端：&lt;br&gt;方法：POST&lt;br&gt;参数：columnList &amp;nbsp;Health&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;columnList &amp;nbsp;Sport&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;拥有相同的name即可。&amp;nbsp;&lt;br&gt;&lt;br&gt;服务器端：&lt;br&gt;&lt;br&gt;Servlet方式：request.getParameterValues(&amp;quot;columnList&amp;quot;);可以得到String数组&lt;br&gt; &lt;br&gt;SpringMVC注解方式：@RequestParameter(&amp;quot;columnList&amp;quot;) String[] list; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //数组形式&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @RequestParameter(&amp;quot;columnList&amp;quot;) List&amp;lt;String&amp;gt; list; &amp;nbsp; //List形式&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @ModelAttribute MyModel model; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //模型中带有数组或者List&lt;br&gt; &lt;br&gt;public class&amp;nbsp;MyModel&amp;nbsp;{&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;List&amp;lt;String&amp;gt; list;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;或者String[] list;&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;......&lt;br&gt;}&lt;/td&gt;&lt;td class=&quot;netInfoParamValue &quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; </description><link>http://swinging-breeze.blogspot.com/2010/03/notespring-mvclist.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-5088432391289585571</guid><pubDate>Fri, 26 Mar 2010 03:16:00 +0000</pubDate><atom:updated>2010-03-25T20:16:48.561-07:00</atom:updated><title>[note][转]外部引入CSS 的两种方式link和@import的区别</title><description>&lt;div&gt;转自：&lt;a href=&quot;http://playgoogle.com/?p=210&quot;&gt;http://playgoogle.com/?p=210&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;本质上，这两种方式都是为了加载CSS文件，但还是存在着细微的差别。&lt;br&gt;&lt;ul&gt;&lt;li&gt;老祖宗的差别。link属于XHTML标签，而@import完全是CSS提供的一种方式。link标签除了可以加载CSS外，还可以做很多其它的事情，比如定义RSS，定义rel连接属性等，@import就只能加载CSS了。&lt;/li&gt; &lt;li&gt;加载顺序的差别。当一个页面被加载的时候（就是被浏览者浏览的时候），link引用的CSS会同时被加载，而@import引用的CSS 会等到页面全部被下载完再被加载。所以有时候浏览@import加载CSS的页面时开始会没有样式，然后突然样式会出现，网速慢的时候还挺明显。&lt;/li&gt;&lt;li&gt;兼容性的差别。由于@import是CSS2.1提出的所以老的浏览器不支持，@import只有在IE5以上的才能识别，而link标签无此问题。&lt;/li&gt; &lt;li&gt;使用dom控制样式时的差别。当使用javascript控制dom去改变样式的时候，只能使用link标签，因为@import不是dom可以控制的。&lt;/li&gt;&lt;/ul&gt;所以，无特殊情况推荐使用link来引入样式，尽量避免使用@import </description><link>http://swinging-breeze.blogspot.com/2010/03/notecss-linkimport.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-6116213612532852285</guid><pubDate>Wed, 24 Mar 2010 04:55:00 +0000</pubDate><atom:updated>2010-03-23T22:09:39.288-07:00</atom:updated><title>[note][转]javascript 中Object.prototype的几个方法</title><description>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; &quot;&gt;&lt;p&gt;&lt;font class=&quot;Apple-style-span&quot; color=&quot;#0479A7&quot; face=&quot;Verdana&quot; size=&quot;3&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 12px;&quot;&gt;&lt;b&gt;转自：&lt;a href=&quot;http://playgoogle.com/?p=198&quot;&gt;http://playgoogle.com/?p=198&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=&quot;color: rgb(4, 121, 167); font-family: Verdana; font-size: 9pt; &quot;&gt;&lt;strong&gt;&lt;br&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(4, 121, 167); font-family: Verdana; font-size: 9pt; &quot;&gt;&lt;strong&gt;hasOwnProperty(property)&lt;br&gt; &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: black; font-size: 9pt; &quot;&gt;&lt;span&gt;判断对象是否有某个特定的属性。必须用字符串指定该属性。（例如，&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;o.hasOwnProperty(&amp;ldquo;name&amp;rdquo;)&lt;/span&gt;&lt;span&gt;），返回布尔值。此方法无法检查该对象的原型链中是否具有该属性；该属性必须是对象本身的一个成员。&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: black; font-size: 9pt; &quot;&gt;&lt;span&gt;如下代码：&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 9pt; &quot;&gt;var s =&amp;rdquo;&amp;quot;;&lt;br&gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: black; font-size: 9pt; &quot;&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;alert(s.hasOwnProperty(&amp;ldquo;split&amp;rdquo;));&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Wingdings; &quot;&gt;è&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;return false&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: black; font-size: 9pt; &quot;&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;alert(String.prototype.hasOwnProperty(&amp;ldquo;split&amp;rdquo;));&lt;/span&gt;&lt;span style=&quot;font-family: Wingdings; &quot;&gt;è&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;return true&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(4, 121, 167); font-family: Verdana; font-size: 9pt; &quot;&gt;&lt;strong&gt;isPrototypeOf(object)&lt;br&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: black; font-size: 9pt; &quot;&gt;&lt;span&gt;判断该对象是否为另一个对象的原型。&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 9pt; &quot;&gt;obj1.isPrototypeOf(obj2);&lt;br&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: black; font-size: 9pt; &quot;&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;obj1&lt;/span&gt;&lt;span&gt;是一个对象的实例；&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;obj2&lt;/span&gt;&lt;span&gt;是另一个将要检查其原型链的对象。原型链可以用来在同一个对象类型的不同实例之间共享功能。如果&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;obj2&lt;/span&gt;&lt;span&gt;的原型链中包含&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;obj1&lt;/span&gt;&lt;span&gt;，那么&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;isPrototypeOf&amp;nbsp;&lt;/span&gt;&lt;span&gt;方法返回&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&amp;nbsp;true&lt;/span&gt;&lt;span&gt;。如果&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;obj2&lt;/span&gt;&lt;span&gt;不是一个对象或者&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;obj1&lt;/span&gt;&lt;span&gt;没有出现在&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;obj2&lt;/span&gt;&lt;span&gt;中的原型链中，&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;isPrototypeOf&amp;nbsp;&lt;/span&gt;&lt;span&gt;方法将返回&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&amp;nbsp;false&lt;/span&gt;&lt;span&gt;。&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(4, 121, 167); font-family: Verdana; font-size: 9pt; &quot;&gt;&lt;strong&gt;propertyIsEnumerable()&lt;br&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: black; font-size: 9pt; &quot;&gt;&lt;span&gt;判断给定的属性是否可以用&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&amp;nbsp;for&amp;hellip;in&amp;nbsp;&lt;/span&gt;&lt;span&gt;语句进行枚举&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;,&lt;/span&gt;&lt;span&gt;返回布尔值。&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(4, 121, 167); font-family: Verdana; font-size: 9pt; &quot;&gt;&lt;strong&gt;toString()&lt;br&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: black; font-size: 9pt; &quot;&gt;&lt;span&gt;返回对象的原始字符串表示。对于&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&amp;nbsp;Object&amp;nbsp;&lt;/span&gt;&lt;span&gt;对象，&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;ECMA-262&amp;nbsp;&lt;/span&gt;&lt;span&gt;没有定义这个值，所以不同的&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&amp;nbsp;ECMAScript&amp;nbsp;&lt;/span&gt;&lt;span&gt;实现具有不同的值。&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(4, 121, 167); font-family: Verdana; font-size: 9pt; &quot;&gt;&lt;strong&gt;toLocaleString()&lt;br&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: black; font-size: 9pt; &quot;&gt;&lt;span&gt;在&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;Object&lt;/span&gt;&lt;span&gt;中和&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;toString()&lt;/span&gt;&lt;span&gt;方法的实现方式一样，但在其他类中有特定的实现，如在&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;Date&lt;/span&gt;&lt;span&gt;中&lt;/span&gt;&lt;span&gt;，&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;toLocaleString()&amp;nbsp;&lt;/span&gt;&lt;span&gt;方法可根据本地时间把&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&amp;nbsp;Date&amp;nbsp;&lt;/span&gt;&lt;span&gt;对象转换为字符串，并返回结果。&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(4, 121, 167); font-family: Verdana; font-size: 9pt; &quot;&gt;&lt;strong&gt;valueOf()&lt;br&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: black; font-size: 9pt; &quot;&gt;&lt;span&gt;返回最适合该对象的原始值。对于许多对象，该方法返回的值都与&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&amp;nbsp;toString()&amp;nbsp;&lt;/span&gt;&lt;span&gt;的返回值相同。&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: black; font-size: 9pt; &quot;&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;&lt;span&gt;以上&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;6&lt;/span&gt;&lt;span&gt;个方法都是&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;Object.prototype&lt;/span&gt;&lt;span&gt;上定义的，&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;ECMAScript&amp;nbsp;&lt;/span&gt;&lt;span&gt;中的所有对象都由&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;Object&lt;/span&gt;&lt;span&gt;继承而来，所以在&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; &quot;&gt;ECMAScript&lt;/span&gt;&lt;span&gt;上的所有对象都具有以几&lt;/span&gt;&lt;span&gt;个方法。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;img src=&quot;http://www1.feedsky.com/t1/345321688/PlayGoogleKarry/feedsky/s.gif?r=http://playgoogle.com/?p=198&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot;&gt;&lt;/span&gt; </description><link>http://swinging-breeze.blogspot.com/2010/03/notejavascript-objectprototype.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-569333447737342051</guid><pubDate>Fri, 19 Mar 2010 16:07:00 +0000</pubDate><atom:updated>2010-03-19T09:08:18.900-07:00</atom:updated><title></title><description>&lt;div&gt;Broadcom Corporation BCM4312 802.11b/g&lt;div&gt;Intel(R) Pentium(R) Dual &amp;nbsp;CPU &amp;nbsp;T2370 &amp;nbsp;@ 1.73GHz&lt;/div&gt;&lt;div&gt;8600M GT&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: ΢���ź�; font-size: 24px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); border-collapse: collapse; color: rgb(255, 0, 0); &quot;&gt;bootsect /nt60 SYS /mbr /force&lt;/span&gt; &lt;/div&gt;&lt;div&gt;&lt;/div&gt;</description><link>http://swinging-breeze.blogspot.com/2010/03/broadcom-corporation-bcm4312-802.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-3524238040525729301</guid><pubDate>Thu, 18 Mar 2010 02:04:00 +0000</pubDate><atom:updated>2010-03-17T19:04:55.209-07:00</atom:updated><title>[note]display:inline及与float:left用途详细区分与特征说明</title><description>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Tahoma, Verdana; font-size: 12px; line-height: 19px; &quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;首先我们要明确，display:inline;与float:left;正确含义。display:inline;(内联)《CSS权威指南》中文字显示：任何不是块级元素的可见元素都是内联元素。其表现的特性是&amp;ldquo;行布局&amp;rdquo;形式，这里的&amp;ldquo;行布局&amp;rdquo;的意思就是说其表现形式始终以行进行显示。比如，我们设定一个内联元素border-bottom:1px&amp;nbsp;solid&amp;nbsp;#000;时其表现是以每行进行重复，每一行下方都会有一条黑色的细线。如果是块级元素那么所显示的的黑线只会在块的下方出现。&lt;br&gt; &lt;br&gt;　　当然这看起来不像是display:inline;与float:left;的区别所在，但是当理解了float:left;的特性那么我们就清楚到底是怎么回事了。float:left;(左浮动)他使得指定元素脱离普通的文档流而产生的特别的布局特性。并且FLOAT必需应用在块级元素之上，也就是说浮动并不应用于内联标签。或者换句话来说当应用了FLOAT那么这个元素将被指定为块级元素。&lt;br&gt;&lt;br&gt;　　那么我们很清楚了，内联(display:inline;)元素不能设置宽高，因为内联属于行布局，其特性是在一行里进行布局，所以不能被设定宽高。&lt;/span&gt; </description><link>http://swinging-breeze.blogspot.com/2010/03/notedisplayinlinefloatleft.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-8401834258355978283</guid><pubDate>Thu, 11 Mar 2010 05:50:00 +0000</pubDate><atom:updated>2010-03-10T21:50:35.978-08:00</atom:updated><title>[note]Spring MultipartFile类解决文件上传问题</title><description>&lt;div&gt;使用MultipartFile类解决文件的上传十分方便，代码如下：&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;@RequestMapping(value = &amp;quot;/member/spaceBackground.do&amp;quot;, method = RequestMethod.POST)&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;	&lt;/span&gt;public void processSetupBackground(Model model, HttpServletResponse resp, HttpServletRequest req, &lt;font class=&quot;Apple-style-span&quot; color=&quot;#FF0000&quot;&gt;@RequestParam(&amp;quot;fileupload&amp;quot;) MultipartFile fileupload&lt;/font&gt;) {&lt;/div&gt; &lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;		&lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;			&lt;/span&gt;String logoName = &amp;quot;logonai.gif&amp;quot;;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;			&lt;/span&gt;String filePath = ProjectEnv.getWebappPath() + &amp;quot;/images/&amp;quot;;&lt;/div&gt; &lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;			&lt;/span&gt;FileTools.input2File(filePath, &lt;font class=&quot;Apple-style-span&quot; color=&quot;#FF0000&quot;&gt;fileupload.getInputStream(),&lt;/font&gt; logoName, true); &lt;font class=&quot;Apple-style-span&quot; color=&quot;#3333FF&quot;&gt;&amp;nbsp;//将上传的文件用input流的方式传到文件logonai.gif中&lt;/font&gt;&lt;/div&gt; &lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;			&lt;/span&gt;PrintWriter out = resp.getWriter();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;			&lt;/span&gt;out.print(&amp;quot;true&amp;quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;			&lt;/span&gt;out.close();&lt;/div&gt; &lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;		&lt;/span&gt;} catch (Exception e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;			&lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;			&lt;/span&gt;logger.error(e.getMessage(), e);&lt;/div&gt; &lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;		&lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;	&lt;/span&gt;}&lt;/div&gt; </description><link>http://swinging-breeze.blogspot.com/2010/03/notespring-multipartfile.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-2372320622573052812</guid><pubDate>Wed, 10 Mar 2010 14:15:00 +0000</pubDate><atom:updated>2010-03-10T06:15:45.263-08:00</atom:updated><title>[note]真正的JSON格式</title><description>以前我写JSON时是这样写的：{name:&amp;#39;zmm&amp;#39;,career:&amp;#39;programmer&amp;#39;}&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;今天发现有两个错误：&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;第一：JSON官方标准里面说明了不用单引号而必须用双引号。&lt;/div&gt;&lt;div&gt;第二：JSON官方标准里面String必须用双引号包裹，而key使用String表示。&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt; &lt;div&gt;下面是正确的JSON：&lt;/div&gt;&lt;div&gt;{&amp;quot;name&amp;quot;:&amp;quot;zmm&amp;quot;,&amp;quot;career&amp;quot;:&amp;quot;programmer&amp;quot;}&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;如果用Java那么需要放到String里面，如下：&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;String json = &amp;quot;{\&amp;quot;name\&amp;quot;:\&amp;quot;zmm\&amp;quot;,\&amp;quot;career\&amp;quot;:\&amp;quot;programmer\&amp;quot;}&amp;quot;;&lt;/div&gt; &lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;使用转义符&amp;quot; \ &amp;quot;。&lt;/div&gt; </description><link>http://swinging-breeze.blogspot.com/2010/03/notejson.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-2864548564031805240</guid><pubDate>Fri, 05 Mar 2010 03:36:00 +0000</pubDate><atom:updated>2010-03-04T19:36:52.035-08:00</atom:updated><title>[note]jQuery选择符转义</title><description>jQuery的选择符中如果有特殊字符如&quot;#&quot;、&quot;.&quot;。那么需要进行转义，很容易只要在特殊字符前加上&quot;\\&quot;即可，如&amp;quot;.\\.show&amp;quot;，查找的是类名为&quot;.show&quot;的节点。&lt;br&gt; </description><link>http://swinging-breeze.blogspot.com/2010/03/notejquery.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-5450202212175694707</guid><pubDate>Tue, 02 Mar 2010 12:23:00 +0000</pubDate><atom:updated>2010-03-02T04:23:35.127-08:00</atom:updated><title>[note][转]使用Iterator 或for-each注意：java.util.ConcurrentModificationException</title><description>原帖：&lt;a href=&quot;http://www.blogjava.net/fingki/archive/2010/03/02/314268.html&quot;&gt;http://www.blogjava.net/fingki/archive/2010/03/02/314268.html&lt;/a&gt;&lt;br&gt;&lt;br&gt;在使用Iterator处理Collection时，注意java.util.ConcurrentModificationException。&lt;br&gt; 1.如果你仅仅是对collection进行遍历查询，那么不必担心什么。&lt;br&gt; 2.但如果你在遍历过程中要对collection进行删除，那么你就要注意了。&lt;br&gt; For example:&lt;br&gt; private&amp;nbsp;void&amp;nbsp;testDel()&amp;nbsp;{&amp;nbsp;&amp;nbsp; &lt;ol&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;String&amp;gt;&amp;nbsp;list&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ArrayList&amp;lt;String&amp;gt;();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for&amp;nbsp;(int&amp;nbsp;i&amp;nbsp;=&amp;nbsp;0;&amp;nbsp;i&amp;nbsp;&amp;lt;&amp;nbsp;10;&amp;nbsp;i++)&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String&amp;nbsp;str&amp;nbsp;=&amp;nbsp;&amp;quot;td&amp;quot;&amp;nbsp;+&amp;nbsp;i;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;list.add(str);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for&amp;nbsp;(Iterator&amp;nbsp;it&amp;nbsp;=&amp;nbsp;list.iterator();&amp;nbsp;it.hasNext();)&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String&amp;nbsp;str&amp;nbsp;=&amp;nbsp;(String)&amp;nbsp;it.next();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(str.equals(&amp;quot;td5&amp;quot;))&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;list.remove(str);&amp;nbsp;&amp;nbsp;// 删除方法一&amp;nbsp; &lt;br&gt;      &lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;it.remove();&amp;nbsp;&amp;nbsp;// 删除方法二&amp;nbsp; &lt;br&gt;     &lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;}&amp;nbsp; &lt;br&gt;     &lt;/li&gt;&lt;/ol&gt; 上面的代码运行没有问题，但如果你用&amp;ldquo;方法一&amp;rdquo;替代&amp;ldquo;方法二&amp;rdquo;，则会出现java.util.ConcurrentModificationException。&lt;br&gt; （用for-each遍历也会出个类似问题）&lt;br&gt; 具体原因是可以看一下&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;先看看List中的remove方法源码：&lt;br&gt; &lt;/span&gt; &lt;ol&gt;&lt;li&gt;public&amp;nbsp;boolean&amp;nbsp;remove(Object&amp;nbsp;o)&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(o&amp;nbsp;==&amp;nbsp;null)&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for&amp;nbsp;(int&amp;nbsp;index&amp;nbsp;=&amp;nbsp;0;&amp;nbsp;index&amp;nbsp;&amp;lt;&amp;nbsp;size;&amp;nbsp;index++)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(elementData[index]&amp;nbsp;==&amp;nbsp;null)&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fastRemove(index);&amp;nbsp;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;else&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for&amp;nbsp;(int&amp;nbsp;index&amp;nbsp;=&amp;nbsp;0;&amp;nbsp;index&amp;nbsp;&amp;lt;&amp;nbsp;size;&amp;nbsp;index++)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(o.equals(elementData[index]))&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fastRemove(index);&amp;nbsp;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;private&amp;nbsp;void&amp;nbsp;fastRemove(int&amp;nbsp;index)&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;modCount++;&amp;nbsp;//&amp;nbsp;特别注意这里，这里只增加了modCount的值&amp;nbsp;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;numMoved&amp;nbsp;=&amp;nbsp;size&amp;nbsp;-&amp;nbsp;index&amp;nbsp;-&amp;nbsp;1;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(numMoved&amp;nbsp;&amp;gt;&amp;nbsp;0)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.arraycopy(elementData,&amp;nbsp;index&amp;nbsp;+&amp;nbsp;1,&amp;nbsp;elementData,&amp;nbsp;index,&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;numMoved);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elementData[--size]&amp;nbsp;=&amp;nbsp;null;&amp;nbsp;//&amp;nbsp;Let&amp;nbsp;gc&amp;nbsp;do&amp;nbsp;its&amp;nbsp;work&amp;nbsp;&amp;nbsp;&lt;/li&gt; &lt;li&gt;}&amp;nbsp; &lt;br&gt;     &lt;/li&gt;&lt;/ol&gt; 接着看。删除后得到下一个元素的代码，it.next():&amp;nbsp; it为AbstractList的内部类Iterator的一个实例。&lt;br&gt; &lt;ol&gt;&lt;li&gt;public&amp;nbsp;E&amp;nbsp;next()&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;checkForComodification();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;try&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;E&amp;nbsp;next&amp;nbsp;=&amp;nbsp;get(cursor);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lastRet&amp;nbsp;=&amp;nbsp;cursor++;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;next;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;catch&amp;nbsp;(IndexOutOfBoundsException&amp;nbsp;e)&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;checkForComodification();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;throw&amp;nbsp;new&amp;nbsp;NoSuchElementException();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;final&amp;nbsp;void&amp;nbsp;checkForComodification()&amp;nbsp;{&amp;nbsp; //注意这个方法&lt;br&gt;     &lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(modCount&amp;nbsp;!=&amp;nbsp;expectedModCount)&amp;nbsp; //检查这两个值是否相同&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;throw&amp;nbsp;new&amp;nbsp;ConcurrentModificationException();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;}&amp;nbsp; &lt;br&gt;     &lt;/li&gt;&lt;/ol&gt; 最后看Iterator的remove()方法的源代码：&lt;br&gt; &lt;ol&gt;&lt;li&gt;public&amp;nbsp;void&amp;nbsp;remove()&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(lastRet&amp;nbsp;==&amp;nbsp;-1)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;throw&amp;nbsp;new&amp;nbsp;IllegalStateException();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;checkForComodification();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;try&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AbstractList.this.remove(lastRet);&amp;nbsp;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(lastRet&amp;nbsp;&amp;lt;&amp;nbsp;cursor)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cursor--;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lastRet&amp;nbsp;=&amp;nbsp;-1;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;expectedModCount&amp;nbsp;=&amp;nbsp;modCount;&amp;nbsp;//&amp;nbsp;设置expectedModCount&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;catch&amp;nbsp;(IndexOutOfBoundsException&amp;nbsp;e)&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;throw&amp;nbsp;new&amp;nbsp;ConcurrentModificationException();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;final&amp;nbsp;void&amp;nbsp;checkForComodification()&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(modCount&amp;nbsp;!=&amp;nbsp;expectedModCount)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;throw&amp;nbsp;new&amp;nbsp;ConcurrentModificationException();&amp;nbsp;&amp;nbsp;&lt;/li&gt; &lt;li&gt;}&amp;nbsp; &lt;br&gt;     &lt;/li&gt;&lt;/ol&gt; 这下就明白了，list的remove方法只修改了modCount值，而iterator的remove能同步modCount和expectedModCount.&lt;br&gt; </description><link>http://swinging-breeze.blogspot.com/2010/03/noteiterator-for-eachjavautilconcurrent.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-4932731370998710169</guid><pubDate>Mon, 01 Mar 2010 00:48:00 +0000</pubDate><atom:updated>2010-02-28T16:48:43.894-08:00</atom:updated><title>[note]现有的NoSQL数据库</title><description>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Tahoma, verdana, arial, helvetica, sans-serif; font-size: 14px; line-height: 22px; &quot;&gt;&lt;p&gt;* &lt;a href=&quot;http://en.wikipedia.org/wiki/Cassandra_(database)&quot; style=&quot;color: rgb(0, 130, 255); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; text-decoration: none; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-width: initial; border-color: initial; &quot;&gt;Cassandra&lt;/a&gt;&lt;br&gt; * &lt;a href=&quot;http://en.wikipedia.org/wiki/Chordless&quot; style=&quot;color: rgb(0, 130, 255); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; text-decoration: none; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-width: initial; border-color: initial; &quot;&gt;Chordless&lt;/a&gt;&lt;br&gt; * &lt;a href=&quot;http://en.wikipedia.org/wiki/CouchDB&quot; style=&quot;color: rgb(0, 130, 255); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; text-decoration: none; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-width: initial; border-color: initial; &quot;&gt;CouchDB&lt;/a&gt;&lt;br&gt; * &lt;a href=&quot;http://en.wikipedia.org/wiki/Db4o&quot; style=&quot;color: rgb(0, 130, 255); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; text-decoration: none; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-width: initial; border-color: initial; &quot;&gt;Db4o&lt;/a&gt;&lt;br&gt; * &lt;a href=&quot;http://en.wikipedia.org/wiki/GT.M&quot; style=&quot;color: rgb(0, 130, 255); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; text-decoration: none; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-width: initial; border-color: initial; &quot;&gt;GT.M&lt;/a&gt;&lt;br&gt; * &lt;a href=&quot;http://en.wikipedia.org/wiki/Hbase&quot; style=&quot;color: rgb(0, 130, 255); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; text-decoration: none; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-width: initial; border-color: initial; &quot;&gt;Hbase&lt;/a&gt;&lt;br&gt; * &lt;a href=&quot;http://en.wikipedia.org/wiki/Hypertable&quot; style=&quot;color: rgb(0, 130, 255); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; text-decoration: none; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-width: initial; border-color: initial; &quot;&gt;Hypertable&lt;/a&gt;&lt;br&gt; * &lt;a href=&quot;http://en.wikipedia.org/wiki/Memcachedb&quot; style=&quot;color: rgb(0, 130, 255); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; text-decoration: none; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-width: initial; border-color: initial; &quot;&gt;Memcachedb&lt;/a&gt;&lt;br&gt; * &lt;a href=&quot;http://en.wikipedia.org/wiki/Mnesia&quot; style=&quot;color: rgb(0, 130, 255); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; text-decoration: none; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-width: initial; border-color: initial; &quot;&gt;Mnesia&lt;/a&gt;&lt;br&gt; * &lt;a href=&quot;http://en.wikipedia.org/wiki/MongoDB&quot; style=&quot;color: rgb(0, 130, 255); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; text-decoration: none; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-width: initial; border-color: initial; &quot;&gt;MongoDB&lt;/a&gt;&lt;br&gt; * &lt;a href=&quot;http://en.wikipedia.org/wiki/Neo4j&quot; style=&quot;color: rgb(0, 130, 255); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; text-decoration: none; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-width: initial; border-color: initial; &quot;&gt;Neo4j&lt;/a&gt;&lt;br&gt; * &lt;a href=&quot;http://en.wikipedia.org/wiki/Project_Voldemort&quot; style=&quot;color: rgb(0, 130, 255); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; text-decoration: none; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-width: initial; border-color: initial; &quot;&gt;Project Voldemort&lt;/a&gt;&lt;br&gt; * &lt;a href=&quot;http://en.wikipedia.org/wiki/Redis_(dbms)&quot; style=&quot;color: rgb(0, 130, 255); border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; text-decoration: none; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-width: initial; border-color: initial; &quot;&gt;Redis&lt;/a&gt;&lt;/p&gt; &lt;/span&gt; </description><link>http://swinging-breeze.blogspot.com/2010/02/notenosql.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-7925702032074952227</guid><pubDate>Sat, 27 Feb 2010 09:49:00 +0000</pubDate><atom:updated>2010-02-27T01:49:05.965-08:00</atom:updated><title>[note]js执行函数的方法以及获取windows的特殊方法</title><description>&lt;div&gt;代码：&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;blockquote class=&quot;gmail_quote&quot; style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; &quot;&gt; function mm(){&lt;/blockquote&gt;&lt;blockquote class=&quot;gmail_quote&quot; style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; &quot;&gt; &amp;nbsp;&amp;nbsp; this.say=function(){&lt;/blockquote&gt;&lt;blockquote class=&quot;gmail_quote&quot; style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; &quot;&gt; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; alert(&amp;quot;sss&amp;quot;);&lt;/blockquote&gt;&lt;blockquote class=&quot;gmail_quote&quot; style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; &quot;&gt; &amp;nbsp;&amp;nbsp; }&lt;/blockquote&gt;&lt;blockquote class=&quot;gmail_quote&quot; style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; &quot;&gt; }&lt;/blockquote&gt;&lt;blockquote class=&quot;gmail_quote&quot; style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; &quot;&gt; &lt;br&gt;&lt;/blockquote&gt;&lt;blockquote class=&quot;gmail_quote&quot; style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; &quot;&gt; m= new mm();&lt;/blockquote&gt;&lt;blockquote class=&quot;gmail_quote&quot; style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; &quot;&gt; m[&amp;#39;say&amp;#39;]();&lt;/blockquote&gt;&lt;blockquote class=&quot;gmail_quote&quot; style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; &quot;&gt; console.log([].sort.call());&lt;/blockquote&gt;&lt;blockquote class=&quot;gmail_quote&quot; style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; &quot;&gt; console.log([][&amp;quot;sort&amp;quot;][&amp;quot;call&amp;quot;]());&lt;/blockquote&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;[].sort.call()就是window，因为sort函数，是对数组的排序。call函数如果没有参数就用全局对象。如果使用sort方法的对象没有可排列的数组那么返回对象本身。&lt;/div&gt; </description><link>http://swinging-breeze.blogspot.com/2010/02/notejswindows.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-3202934512820515845</guid><pubDate>Sat, 27 Feb 2010 06:13:00 +0000</pubDate><atom:updated>2010-02-26T22:13:37.410-08:00</atom:updated><title>[转][精品]浏览器缓存机制</title><description>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: 微软雅黑; font-size: medium; &quot;&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; &lt;a name=&quot;N100C5&quot;&gt;&lt;span class=&quot;smalltitle&quot; style=&quot;font-size: 1.2em; font-weight: bold; &quot;&gt;Cache-Control&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; Cache-Control 是最重要的规则。这个字段用于指定所有缓存机制在整个请求/响应链中&lt;strong&gt;必须&lt;/strong&gt;服从的指令。这些指令指定用于阻止缓存对请求或响应造成不利干扰的行为。这些指令通常覆盖默认缓存算法。缓存指令是单向的，即请求中存在一个指令并不意味着响应中将存在同一个指令。&lt;/p&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; cache-control 定义是：Cache-Control = &amp;quot;Cache-Control&amp;quot; &amp;quot;:&amp;quot; cache-directive。表 1 展示了适用的值。&lt;/p&gt;&lt;br&gt;&lt;a name=&quot;table1&quot;&gt;&lt;b style=&quot;font-size: 0.76em; font-weight: bold; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-family: arial, sans-serif; &quot;&gt;表 1. 常用 cache-directive 值&lt;/b&gt;&lt;/a&gt;&lt;br&gt; &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;data-table-1&quot; summary=&quot;Table explaining the cache-directive values&quot; width=&quot;100%&quot; style=&quot;font-size: 0.8em; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); margin-bottom: 8px; width: 708px; &quot;&gt; &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Cache-directive&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; 说明&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; public&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 所有内容都将被缓存&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; private&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容只缓存到私有缓存中&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; no-cache&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 所有内容都不会被缓存&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; no-store&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 所有内容都不会被缓存到缓存或 Internet 临时文件中&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; must-revalidation/proxy-revalidation&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 如果缓存的内容失效，请求必须发送到服务器/代理以进行重新验证&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; max-age=xxx (xxx is numeric)&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 缓存的内容将在&amp;nbsp;&lt;em&gt;xxx&lt;/em&gt;&amp;nbsp;秒后失效&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; 表 2 表明在不同的情形下，浏览器是将请求重新发送到服务器还是使用缓存的内容。&lt;/p&gt;&lt;br&gt;&lt;a name=&quot;table2&quot;&gt;&lt;b style=&quot;font-size: 0.76em; font-weight: bold; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-family: arial, sans-serif; &quot;&gt;表 2. 对 cache-directive 值的浏览器响应&lt;/b&gt;&lt;/a&gt;&lt;br&gt; &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;data-table-1&quot; summary=&quot;Table showing the browser&amp;#39;s response to cash-direcctive values&quot; width=&quot;100%&quot; style=&quot;font-size: 0.8em; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); margin-bottom: 8px; width: 708px; &quot;&gt; &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Cache-directive&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; 打开一个新的浏览器窗口&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; 在原窗口中单击 Enter 按钮&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; 刷新&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; 单击 Back 按钮&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; public&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; private&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 第一次，浏览器重新发送请求到服务器；此后，浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; no-cache/no-store&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; must-revalidation/proxy-revalidation&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 第一次，浏览器重新发送请求到服务器；此后，浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; max-age=xxx (xxx is numeric)&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 在&amp;nbsp;&lt;em&gt;xxx&lt;/em&gt;&amp;nbsp;秒后，浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 在&amp;nbsp;&lt;em&gt;xxx&lt;/em&gt;&amp;nbsp;秒后，浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 在&amp;nbsp;&lt;em&gt;xxx&lt;/em&gt;&amp;nbsp;秒后，浏览器重新发送请求到服务器&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; Cache-Control 是关于浏览器缓存的最重要的设置，因为它覆盖其他设置，比如 Expires 和 Last-Modified。另外，由于浏览器的行为基本相同，这个属性是处理跨浏览器缓存问题的最有效的方法。&lt;/p&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; &lt;a name=&quot;N1019B&quot;&gt;&lt;span class=&quot;smalltitle&quot; style=&quot;font-size: 1.2em; font-weight: bold; &quot;&gt;失效&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; Expires 头部字段提供一个日期和时间，响应在该日期和时间后被认为失效。失效的缓存条目通常不会被缓存（无论是代理缓存还是用户代理缓存）返回，除非首先通过原始服务器（或者拥有该实体的最新副本的中介缓存）验证。（&lt;strong&gt;注意：&lt;/strong&gt;cache-control max-age 和 s-maxage 将覆盖 Expires 头部。）&lt;/p&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; Expires 字段接收以下格式的值：&amp;ldquo;Expires: Sun, 08 Nov 2009 03:37:26 GMT&amp;rdquo;。如果查看内容时的日期在给定的日期之前，则认为该内容没有失效并从缓存中提取出来。反之，则认为该内容失效，缓存将采取一些措施。表 3-6 表明针对不同用户操作的不同浏览器的行为。&lt;/p&gt;&lt;br&gt;&lt;a name=&quot;table3&quot;&gt;&lt;b style=&quot;font-size: 0.76em; font-weight: bold; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-family: arial, sans-serif; &quot;&gt;表 3. 当用户打开一个新的浏览器窗口时的失效操作&amp;nbsp;&lt;/b&gt;&lt;/a&gt;&lt;br&gt; &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;data-table-1&quot; summary=&quot;Table explaining expiration actions with a new browser window&quot; width=&quot;100%&quot; style=&quot;font-size: 0.8em; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); margin-bottom: 8px; width: 708px; &quot;&gt; &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; &lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Firefox 3.5&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; IE 8&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Chrome 3&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容没有失效&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容失效&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br&gt;&lt;a name=&quot;table4&quot;&gt;&lt;b style=&quot;font-size: 0.76em; font-weight: bold; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-family: arial, sans-serif; &quot;&gt;表 4. 当用户在原始浏览器窗口中单击 Enter 按钮时的失效操作&lt;/b&gt;&lt;/a&gt;&lt;br&gt; &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;data-table-1&quot; summary=&quot;Table explaining expiration actions when Enter is pressed in the                 original browser window&quot; width=&quot;100%&quot; style=&quot;font-size: 0.8em; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); margin-bottom: 8px; width: 708px; &quot;&gt; &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; &lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Firefox 3.5&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; IE 8&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Chrome 3&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容没有失效&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容失效&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br&gt;&lt;a name=&quot;table5&quot;&gt;&lt;b style=&quot;font-size: 0.76em; font-weight: bold; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-family: arial, sans-serif; &quot;&gt;表 5. 当用户按 F5 键刷新页面时的失效操作&lt;/b&gt;&lt;/a&gt;&lt;br&gt; &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;data-table-1&quot; summary=&quot;Table explaining actions when F5 is pressed&quot; width=&quot;100%&quot; style=&quot;font-size: 0.8em; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); margin-bottom: 8px; width: 708px; &quot;&gt; &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; &lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Firefox 3.5&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; IE 8&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Chrome 3&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容没有失效&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容失效&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br&gt;&lt;a name=&quot;table6&quot;&gt;&lt;b style=&quot;font-size: 0.76em; font-weight: bold; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-family: arial, sans-serif; &quot;&gt;表 6. 当用户单击 Back 或 Forward 按钮时的失效操作&lt;/b&gt;&lt;/a&gt;&lt;br&gt; &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;data-table-1&quot; summary=&quot;Table explaining expiration actions when Back or Forward are                 pressed&quot; width=&quot;100%&quot; style=&quot;font-size: 0.8em; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); margin-bottom: 8px; width: 708px; &quot;&gt; &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; &lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Firefox 3.5&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; IE 8&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Chrome 3&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容没有失效&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容失效&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; &lt;strong&gt;注意：&lt;/strong&gt;所有浏览器都假定为使用默认设置运行。&lt;/p&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; &lt;a name=&quot;N102A9&quot;&gt;&lt;span class=&quot;smalltitle&quot; style=&quot;font-size: 1.2em; font-weight: bold; &quot;&gt;Last-Modified/E-Tag&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; Last-Modified 实体头部字段值通常用作一个缓存验证器。简单来说，如果实体值在 Last-Modified 值之后没有被更改，则认为该缓存条目有效。ETag 响应头部字段值是一个实体标记，它提供一个 &amp;ldquo;不透明&amp;rdquo; 的缓存验证器。这可能在以下几种情况下提供更可靠的验证：不方便存储修改日期；HTTP 日期值的 one-second 解决方案不够用；或者原始服务器希望避免由于使用修改日期而导致的某些冲突。&lt;/p&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; 不同的浏览器有不同的配置行为。表 7-10 表明针对不同用户操作的不同浏览器的行为。&lt;/p&gt;&lt;br&gt;&lt;a name=&quot;table7&quot;&gt;&lt;b style=&quot;font-size: 0.76em; font-weight: bold; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-family: arial, sans-serif; &quot;&gt;表 7. 当用户打开一个新的浏览器窗口时的 Last-Modified E-Tag 操作&amp;nbsp;&lt;/b&gt;&lt;/a&gt;&lt;br&gt; &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;data-table-1&quot; summary=&quot;Table explaining the Last-Modified E-Tag action in different                 browsers&quot; width=&quot;100%&quot; style=&quot;font-size: 0.8em; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); margin-bottom: 8px; width: 708px; &quot;&gt; &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; &lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Firefox 3.5&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; IE 8&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Chrome 3&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容自上次访问以来没有被修改&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容自上次访问以来已经被修改&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br&gt;&lt;a name=&quot;table8&quot;&gt;&lt;b style=&quot;font-size: 0.76em; font-weight: bold; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-family: arial, sans-serif; &quot;&gt;表 8. 当用户在原始浏览器窗口中单击 Enter 按钮时的 Last-Modified E-Tag 操作&lt;/b&gt;&lt;/a&gt;&lt;br&gt; &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;data-table-1&quot; summary=&quot;Table explaining the Last-Modified E-Tag action when Enter is                 pressed&quot; width=&quot;100%&quot; style=&quot;font-size: 0.8em; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); margin-bottom: 8px; width: 708px; &quot;&gt; &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; &lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Firefox 3.5&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; IE 8&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Chrome 3&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容自上次访问以来没有被修改&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容自上次访问以来已经被修改&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br&gt;&lt;a name=&quot;table9&quot;&gt;&lt;b style=&quot;font-size: 0.76em; font-weight: bold; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-family: arial, sans-serif; &quot;&gt;表 9. 当用户按 F5 键刷新页面时的 Last-Modified E-Tag 操作&lt;/b&gt;&lt;/a&gt;&lt;br&gt; &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;data-table-1&quot; summary=&quot;Table explaining Last-Modified E-Tag action when F5 is pressed&quot; width=&quot;100%&quot; style=&quot;font-size: 0.8em; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); margin-bottom: 8px; width: 708px; &quot;&gt; &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; &lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Firefox 3.5&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; IE 8&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Chrome 3&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容自上次访问以来没有被修改&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容自上次访问以来已经被修改&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br&gt;&lt;a name=&quot;table10&quot;&gt;&lt;b style=&quot;font-size: 0.76em; font-weight: bold; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-family: arial, sans-serif; &quot;&gt;表 10. 没有缓存设置且用户单击 Back 或 Forward 按钮&lt;/b&gt;&lt;/a&gt;&lt;br&gt; &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;data-table-1&quot; summary=&quot;Table explaining no cache settings when Back and Forward is                 pressed&quot; width=&quot;100%&quot; style=&quot;font-size: 0.8em; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); margin-bottom: 8px; width: 708px; &quot;&gt; &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; &lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Firefox 3.5&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; IE 8&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Chrome 3&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容自上次访问以来没有被修改&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 内容自上次访问以来已经被修改&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; &lt;strong&gt;注意：&lt;/strong&gt;所有浏览器都假定使用默认设置运行。&lt;/p&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; &lt;a name=&quot;N103B3&quot;&gt;&lt;span class=&quot;smalltitle&quot; style=&quot;font-size: 1.2em; font-weight: bold; &quot;&gt;不进行任何缓存相关设置&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; 如果您不定义任何缓存相关设置，则不同的浏览器有不同的行为。有时，同一个浏览器在相同的情形下每次运行时的行为都是不同的。情况可能很复杂。另外，有些不该缓存的内容如果被缓存，将会导致安全问题。&lt;/p&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; 不同的浏览器有不同的行为。表 11 展示了不同的浏览器行为。&lt;/p&gt;&lt;br&gt;&lt;a name=&quot;table11&quot;&gt;&lt;b style=&quot;font-size: 0.76em; font-weight: bold; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-family: arial, sans-serif; &quot;&gt;表 11. 没有缓存设置且用户打开一个新的浏览器窗口&lt;/b&gt;&lt;/a&gt;&lt;br&gt; &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;data-table-1&quot; summary=&quot;Table explaining no cache settings&quot; width=&quot;100%&quot; style=&quot;font-size: 0.8em; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); margin-bottom: 8px; width: 708px; &quot;&gt; &lt;tbody&gt;&lt;tr&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; &lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Firefox 3.5&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; IE 8&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Chrome 3&lt;/th&gt;&lt;th style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; background-image: url(http://www.ibm.com/i/v16/t/text-tabs-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(247, 248, 252); text-align: left; font-size: 0.7em; background-position: initial initial; background-repeat: repeat no-repeat; &quot;&gt; Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 打开一个新页面&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 在原始窗口中单击 Enter 按钮&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面。&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 按 F5 键刷新&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 单击 Back 或 Forward 按钮&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面。&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器呈现来自缓存的页面。&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;font-family: arial, nsimsun, sans-serif; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; font-size: 0.7em; &quot;&gt; 浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style=&quot;font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; &quot;&gt; &lt;strong&gt;注意：&lt;/strong&gt;所有浏览器都假定使用默认设置运行。&lt;/p&gt;&lt;/span&gt; </description><link>http://swinging-breeze.blogspot.com/2010/02/blog-post_26.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-5280114513571715527</guid><pubDate>Fri, 26 Feb 2010 14:58:00 +0000</pubDate><atom:updated>2010-02-26T06:58:22.699-08:00</atom:updated><title>[转][精品]Java的类装载器(Class Loader)和命名空间(NameSpace)</title><description>转自：&lt;a href=&quot;http://blog.csdn.net/lovingprince/archive/2009/06/03/4239491.aspx&quot;&gt;http://blog.csdn.net/lovingprince/archive/2009/06/03/4239491.aspx&lt;/a&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; &quot;&gt;&lt;p style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt; &lt;strong&gt;摘要&lt;/strong&gt;&lt;/p&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;Java的类装载器是Java动态性的核心，本文将向大家简要介绍Java的类装载器，及相关的parent delegation模型，命名空间，运行时包等概念，同时讨论一些在学习中容易混淆的问题。&lt;/p&gt; &lt;p style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;&lt;strong&gt;类装载器的功能及分类&lt;/strong&gt;&lt;/p&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt; 顾名思义，类装载器是用来把类(class)装载进JVM的。JVM规范定义了两种类型的类装载器：启动内装载器(bootstrap)和用户自定义装载器(user-defined class loader)。&lt;/p&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt; bootstrap是JVM自带的类装载器，用来装载核心类库，如java.lang.*等。由例1可以看出，java.lang.Object是由bootstrap装载的。&lt;/p&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt; Java 提供了抽象类ClassLoader，所有用户自定义类装载器都实例化自ClassLoader的子类。 System Class Loader是一个特殊的用户自定义类装载器，由JVM的实现者提供，在编程者不特别指定装载器的情况下默认装载用户类。系统类装载器可以通过 ClassLoader.getSystemClassLoader() 方法得到。&lt;/p&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt; 例1，测试你所使用的JVM的ClassLoader&lt;/p&gt;&lt;pre&gt;/*LoaderSample1.java*/&lt;br&gt; public class LoaderSample1 {&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Class c;&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ClassLoader cl;&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cl = ClassLoader.getSystemClassLoader();&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(cl);&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (cl != null) {&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cl = cl.getParent();&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(cl);&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try {&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c = Class.forName(&amp;quot;java.lang.Object&amp;quot;);&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cl = c.getClassLoader();&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(&amp;quot;java.lang.Object&amp;#39;s loader is &amp;quot; + cl);&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c = Class.forName(&amp;quot;LoaderSample1&amp;quot;);&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cl = c.getClassLoader();&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(&amp;quot;LoaderSample1&amp;#39;s loader is &amp;quot; + cl);&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } catch (Exception e) {&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.printStackTrace();&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt; }&lt;/pre&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;在我的机器上(Sun Java 1.4.2)的运行结果&lt;/p&gt;&lt;pre&gt; sun.misc.Launcher$AppClassLoader@1a0c10f&lt;br&gt; sun.misc.Launcher$ExtClassLoader@e2eec8&lt;br&gt; null &lt;br&gt; java.lang.Object&amp;#39;s loader is null&lt;br&gt; LoaderSample1&amp;#39;s loader is sun.misc.Launcher$AppClassLoader@1a0c10f&lt;br&gt; &lt;/pre&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;第一行表示，系统类装载器实例化自类sun.misc.Launcher$AppClassLoader&lt;/p&gt; &lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;第二行表示，系统类装载器的parent实例化自类sun.misc.Launcher$ExtClassLoader&lt;/p&gt; &lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;第三行表示，系统类装载器parent的parent为bootstrap&lt;/p&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt; 第四行表示，核心类java.lang.Object是由bootstrap装载的&lt;/p&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt; 第五行表示，用户类LoaderSample1是由系统类装载器装载的&lt;/p&gt;&lt;p style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;&lt;strong&gt;parent delegation模型&lt;/strong&gt;&lt;/p&gt; &lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;从 1.2版本开始，Java引入了双亲委托模型，从而更好的保证Java平台的安全。在此模型下，当一个装载器被请求装载某个类时，它首先委托自己的 parent去装载，若parent能装载，则返回这个类所对应的Class对象，若parent不能装载，则由parent的请求者去装载。&lt;/p&gt; &lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;如 图1所示，loader2的parent为loader1，loader1的parent为system class loader。假设loader2被要求装载类MyClass，在parent delegation模型下，loader2首先请求loader1代为装载，loader1再请求系统类装载器去装载MyClass。若系统装载器能成 功装载，则将MyClass所对应的Class对象的reference返回给loader1，loader1再将reference返回给 loader2，从而成功将类MyClass装载进虚拟机。若系统类装载器不能装载MyClass，loader1会尝试装载MyClass，若 loader1也不能成功装载，loader2会尝试装载。若所有的parent及loader2本身都不能装载，则装载失败。&lt;/p&gt; &lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;若 有一个能成功装载，实际装载的类装载器被称为定义类装载器，所有能成功返回Class对象的装载器（包括定义类装载器）被称为初始类装载器。如图1所示， 假设loader1实际装载了MyClass，则loader1为MyClass的定义类装载器，loader2和loader1为MyClass的初始 类装载器。&lt;/p&gt; &lt;p align=&quot;center&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;&lt;img src=&quot;http://gceclub.sun.com.cn/yuanchuang/week-7/java01.gif&quot; border=&quot;0&quot; alt=&quot;&quot; width=&quot;339&quot; height=&quot;318&quot; style=&quot;border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; &quot;&gt;&lt;/p&gt; &lt;p align=&quot;center&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;&lt;strong&gt;图 1 parent delegation模型&lt;/strong&gt;&lt;/p&gt; &lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;需 要指出的是，Class Loader是对象，它的父子关系和类的父子关系没有任何关系。一对父子loader可能实例化自同一个Class，也可能不是，甚至父loader实例 化自子类，子loader实例化自父类。假设MyClassLoader继承自ParentClassLoader，我们可以有如下父子loader：&lt;/p&gt; &lt;pre&gt;ClassLoader loader1 = new MyClassLoader();&lt;br&gt; //参数 loader1 为 parent&lt;br&gt; ClassLoader loader2 = new ParentClassLoader(loader1); &lt;br&gt; &lt;/pre&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;那么parent delegation模型为什么更安全了？因为在此模型下用户自定义的类装载器不可能装载应该由父亲装载器装载的可靠类，从而防止不可靠甚至恶意的代码代 替由父亲装载器装载的可靠代码。实际上，类装载器的编写者可以自由选择不用把请求委托给parent，但正如上所说，会带来安全的问题。&lt;/p&gt; &lt;p style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;&lt;strong&gt;命名空间及其作用&lt;/strong&gt;&lt;/p&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt; 每个类装载器有自己的命名空间，命名空间由所有以此装载器为创始类装载器的类组成。不同命名空间的两个类是不可见的，但只要得到类所对应的Class对象的reference，还是可以访问另一命名空间的类。&lt;/p&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt; 例 2演示了一个命名空间的类如何使用另一命名空间的类。在例子中，LoaderSample2由系统类装载器装载，LoaderSample3由自定义的装 载器loader负责装载，两个类不在同一命名空间，但LoaderSample2得到了LoaderSample3所对应的Class对象的 reference，所以它可以访问LoaderSampl3中公共的成员(如age)。&lt;/p&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt; 例2不同命名空间的类的访问&lt;/p&gt;&lt;pre&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;/*LoaderSample2.java*/&lt;br&gt; import java.net.*;&lt;br&gt; import java.lang.reflect.*;&lt;br&gt; public class LoaderSample2 {&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String[] args) {&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try {&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String path = System.getProperty(&amp;quot;user.dir&amp;quot;);&lt;br&gt; &lt;/span&gt; &lt;span style=&quot;font-family: 宋体; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; URL[] us = {new URL(&amp;quot;file://&amp;quot; + path + &amp;quot;/sub/&amp;quot;)};&lt;br&gt; &lt;/span&gt; &lt;span style=&quot;font-family: 宋体; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ClassLoader loader = new URLClassLoader(us);&lt;br&gt; &lt;/span&gt; &lt;span style=&quot;font-family: 宋体; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Class c = loader.loadClass(&amp;quot;LoaderSample3&amp;quot;);&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Object o = c.newInstance();&lt;br&gt; &lt;/span&gt; &lt;span style=&quot;font-family: 宋体; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Field f = c.getField(&amp;quot;age&amp;quot;);&lt;br&gt; &lt;/span&gt; &lt;span style=&quot;font-family: 宋体; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int age = f.getInt(o);&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(&amp;quot;age is &amp;quot; + age);&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } catch (Exception e) {&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.printStackTrace();&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt; &lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;}&lt;/span&gt; &lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;/*sub/Loadersample3.java*/&lt;br&gt; public class LoaderSample3 {&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; static {&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(&amp;quot;LoaderSample3 loaded&amp;quot;);&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt; &lt;/span&gt; &lt;span style=&quot;font-family: 宋体; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public int age = 30;&lt;br&gt; }&lt;/span&gt; &lt;/pre&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;编译：javac LoaderSample2.java; javac sub/LoaderSample3.java&lt;/p&gt; &lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;运行：java LoaderSample2&lt;/p&gt;&lt;pre&gt;LoaderSample3 loaded&lt;br&gt;  age is 30&lt;br&gt; &lt;/pre&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;从运行结果中可以看出，在类LoaderSample2中可以创建处于另一命名空间的类LoaderSample3中的对象并可以访问其公共成员age。&lt;/p&gt; &lt;p style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;&lt;strong&gt;运行时包(runtime package)&lt;/strong&gt;&lt;/p&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt; 由 同一类装载器定义装载的属于相同包的类组成了运行时包，决定两个类是不是属于同一个运行时包，不仅要看它们的包名是否相同，还要看的定义类装载器是否相 同。只有属于同一运行时包的类才能互相访问包可见的类和成员。这样的限制避免了用户自己的代码冒充核心类库的类访问核心类库包可见成员的情况。假设用户自 己定义了一个类java.lang.Yes，并用用户自定义的类装载器装载，由于java.lang.Yes和核心类库java.lang.*由不同的装 载器装载，它们属于不同的运行时包，所以java.lang.Yes不能访问核心类库java.lang中类的包可见的成员。&lt;/p&gt; &lt;p style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt;&lt;strong&gt;总结&lt;/strong&gt;&lt;/p&gt;&lt;p class=&quot;normal&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; &quot;&gt; 在简单讨论了类装载器，parent delegation模型，命名空间，运行时包后，相信大家已经对它们的作用有了一定的了解。命名空间并没有完全禁止属于不同空间的类的互相访问，双亲委托模型加强了Java的安全，运行时包增加了对包可见成员的保护。&lt;/p&gt;&lt;/span&gt;&lt;/div&gt; </description><link>http://swinging-breeze.blogspot.com/2010/02/javaclass-loadernamespace.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-3565529312365784174</guid><pubDate>Thu, 25 Feb 2010 02:22:00 +0000</pubDate><atom:updated>2010-02-24T18:22:50.085-08:00</atom:updated><title>[note][精品]Javascript编程中的this</title><description>this代表当前作用域的对象。看代码1：&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;name = &amp;quot;Global&amp;quot;;&lt;/div&gt;&lt;div&gt;o = {&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; name:&amp;quot;Object&amp;quot;,&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; show:function() {&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;alert(name);&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;alert(&lt;a href=&quot;http://this.name&quot;&gt;this.name&lt;/a&gt;);&lt;/div&gt; &lt;div&gt;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;o.show();&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;结果为：Global&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Object&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;看代码2：&lt;/div&gt;&lt;div&gt;function a() {&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;alert(this);&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;a();&lt;/div&gt; &lt;div&gt;结果为：[object Window]&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;看代码3：&lt;/div&gt;&lt;div&gt;function a() {&lt;/div&gt;&lt;div&gt;alert(this);&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;new a();&lt;/div&gt;&lt;div&gt;结果为：[object Object]&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;new操作符生成了a对象的this指针。只有对象有指针，function没有，代码1是直接赋值了一个对象，所以也有this指针。但是函数的属性name不想Java那样被看成&lt;a href=&quot;http://this.name&quot;&gt;this.name&lt;/a&gt;，而是&lt;a href=&quot;http://window.name&quot;&gt;window.name&lt;/a&gt;。&lt;/div&gt; &lt;/div&gt; </description><link>http://swinging-breeze.blogspot.com/2010/02/notejavascriptthis.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-3906218305568808382</guid><pubDate>Sat, 20 Feb 2010 07:08:00 +0000</pubDate><atom:updated>2010-02-19T23:08:01.505-08:00</atom:updated><title>[转][精品]Java memory model</title><description>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; &quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; &quot;&gt; &lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;转自：&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal; font-size: 12px; &quot;&gt;&lt;a href=&quot;http://jiangyongyuan.javaeye.com/blog/356579&quot;&gt;http://jiangyongyuan.javaeye.com/blog/356579&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; &quot;&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;br&gt; &lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; &quot;&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;内存模型 (memory model)&lt;br&gt; &lt;/strong&gt;内存模型描述的是程序中各变量（实例域、静态域和数组元素）之间的关系，以及在实际计算机系统中将变量存储到内存和从内存取出变量这样的低层细节.&lt;br&gt;&lt;br&gt;不同平台间的处理器架构将直接影响内存模型的结构.&lt;br&gt;&lt;br&gt;在C或C++中, 可以利用不同操作平台下的内存模型来编写并发程序. 但是, 这带给开发人员的是, 更高的学习成本.&lt;br&gt;相比之下, java利用了自身虚拟机的优势, 使内存模型不束缚于具体的处理器架构, 真正实现了跨平台.&lt;br&gt; (针对hotspot jvm, jrockit等不同的jvm, 内存模型也会不相同)&lt;br&gt;&lt;br&gt;&lt;span&gt;内存模型的特征:&lt;/span&gt;&lt;br&gt;a, Visibility 可视性 (多核,多线程间数据的共享)&lt;br&gt;b, Ordering 有序性 (对内存进行的操作应该是有序的)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;hr style=&quot;height: 1px; margin-top: 1.5em; margin-right: 10px; margin-bottom: 1.5em; margin-left: 10px; border-bottom-color: black; border-bottom-width: thin; border-bottom-style: initial; &quot;&gt; &lt;/span&gt;&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; &quot;&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;span&gt;&lt;br&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;span&gt;java 内存模型&lt;/span&gt;&lt;/strong&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;span&gt;&amp;nbsp;(&lt;/span&gt;&lt;/strong&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;span&gt;java memory model&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;)&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span style=&quot;font-size: small; &quot;&gt;根据Java Language Specification中的说明, jvm系统中存在一个主内存(Main Memory或Java Heap Memory)，Java中所有变量都储存在主存中，对于所有线程都是共享的。&lt;br&gt;&lt;br&gt;每条线程都有自己的工作内存(Working Memory)，工作内存中保存的是主存中某些变量的拷贝，线程对所有变量的操作都是在工作内存中进行，线程之间无法相互直接访问，变量传递均需要通过主存完成。&lt;br&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;其中, 工作内存里的变量, 在多核处理器下, 将大部分储存于处理器高速缓存中, 高速缓存在不经过内存时, 也是不可见的.&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;span&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;jmm怎么体现 可视性(Visibility) ?&lt;/strong&gt;&lt;br&gt;&lt;/span&gt;在jmm中, 通过并发线程修改变量值, 必须将线程变量同步回主存后, 其他线程才能访问到.&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;br&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;jmm怎么体现 有序性(Ordering) ?&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&amp;nbsp;&lt;br&gt;通过java提供的同步机制或volatile关键字, 来保证内存的访问顺序.&amp;nbsp;&lt;/span&gt;&lt;span&gt;&lt;br&gt; &lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;hr style=&quot;height: 1px; margin-top: 1.5em; margin-right: 10px; margin-bottom: 1.5em; margin-left: 10px; border-bottom-color: black; border-bottom-width: thin; border-bottom-style: initial; &quot;&gt; &lt;/span&gt;&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; &quot;&gt;&lt;br&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;span&gt;&lt;span&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;span&gt;缓存一致性（cache coherency）&lt;/span&gt;&lt;/strong&gt;&lt;br&gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;什么是缓存一致性?&lt;/span&gt;&lt;/strong&gt;&lt;br&gt;它是一种管理多处理器系统的高速缓存区结构，其可以保证数据在高速缓存区到内存的传输中不会丢失或重复。(来自wikipedia)&lt;br&gt;&lt;br&gt;举例理解:&lt;br&gt;假如有一个处理器有一个更新了的变量值位于其缓存中，但还没有被写入主内存，这样别的处理器就可能会看不到这个更新的值.&lt;br&gt; &lt;br&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;解决缓存一致性的方法?&lt;/span&gt;&lt;/strong&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;a, 顺序一致性模型:&lt;br&gt;要求某处理器对所改变的变量值立即进行传播, 并确保该值被所有处理器接受后, 才能继续执行其他指令.&lt;/span&gt;&lt;span&gt;&lt;br&gt; &lt;br&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;span&gt;b, 释放一致性模型: (类似jmm cache coherency)&lt;br&gt;允许处理器将改变的变量值延迟到释放锁时才进行传播.&lt;/span&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;hr style=&quot;height: 1px; margin-top: 1.5em; margin-right: 10px; margin-bottom: 1.5em; margin-left: 10px; border-bottom-color: black; border-bottom-width: thin; border-bottom-style: initial; &quot;&gt; &lt;/span&gt;&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; &quot;&gt;&lt;br&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;span&gt;&lt;span&gt;jmm缓存一致性模型 - &amp;quot;happens-before ordering(先行发生排序)&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br&gt; &lt;br&gt;一般情况下的示例程序:&lt;br&gt;&lt;br&gt;x = 0;&lt;br&gt;y = 0;&lt;br&gt;i = 0;&lt;br&gt;j = 0;&lt;br&gt;&lt;br&gt;// thread A&lt;br&gt;y = 1;&lt;br&gt;x = 1;&lt;br&gt;&lt;br&gt;// thread B&lt;br&gt;i = x;&lt;br&gt;j = y;&lt;br&gt;&lt;br&gt;在如上程序中, 如果线程A,B在无保障情况下运行, 那么i,j各会是什么值呢?&lt;br&gt;&lt;br&gt;答案是, 不确定. (00,01,10,11都有可能出现)&lt;br&gt; &lt;span style=&quot;color: rgb(255, 0, 0); &quot;&gt;这里没有使用java同步机制, 所以 jmm 有序性和可视性 都无法得到保障.&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;span&gt;happens-before ordering(&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 0, 0); &quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;先行发生排序)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;如何避免这种情况?&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 0, 0); &quot;&gt;&lt;br&gt; &lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;排序原则已经做到:&lt;/span&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;span style=&quot;color: rgb(255, 0, 0); &quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;a,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 0, 0); &quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;在程序顺序中,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;span style=&quot;color: rgb(255, 0, 0); &quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;线程中的每一个操作, 发生在当前操作后面将要出现的每一个操作之前.&lt;br&gt; b, 对象监视器的解锁发生在等待获取对象锁的线程之前.&lt;br&gt;c, 对volitile关键字修饰的变量写入操作, 发生在对该变量的读取之前.&lt;br&gt;d,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;对一个线程的&amp;nbsp;&lt;code style=&quot;font-family: &amp;#39;Courier New&amp;#39;, Courier, monospace; font-size: 1em; white-space: pre; &quot;&gt;Thread.start()&lt;/code&gt;&amp;nbsp;调用 发生在启动的线程中的所有操作之前.&lt;br&gt; e, 线程中的所有操作 发生在从这个线程的&amp;nbsp;&lt;code style=&quot;font-family: &amp;#39;Courier New&amp;#39;, Courier, monospace; font-size: 1em; white-space: pre; &quot;&gt;Thread.join()&lt;/code&gt;成功返回的所有其他线程之前.&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 0, 0); &quot;&gt;&lt;br&gt; &lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&lt;span style=&quot;font-size: small; &quot;&gt;为了实现&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 0, 0); &quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&lt;span style=&quot;font-size: small; &quot;&gt;happends-before ordering原则, java及jdk提供的工具:&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;a, synchronized关键字&lt;br&gt;b, volatile关键字&lt;br&gt;c, final变量&lt;br&gt;d, java.util.concurrent.locks包(since jdk 1.5)&lt;br&gt;e, java.util.concurrent.atmoic包(since jdk 1.5)&lt;br&gt; ...&lt;br&gt;&lt;/span&gt;&lt;br&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;使用了happens-before ordering的例子:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 0, 0); &quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;img src=&quot;http://www.ibm.com/developerworks/cn/java/j-jtp03304/jsr133.gif&quot; height=&quot;257&quot; alt=&quot;&quot; width=&quot;336&quot; style=&quot;border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; &quot;&gt;&amp;nbsp;&lt;img alt=&quot;&quot; style=&quot;border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; &quot;&gt;&lt;br&gt; &lt;br&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;(1) 获取对象监视器的锁(lock)&lt;br&gt;&lt;br&gt;(2)&amp;nbsp;&lt;span style=&quot;color: rgb(255, 0, 0); &quot;&gt;清空工作内存数据, 从主存复制变量到当前工作内存, 即同步数据 (read and load)&lt;/span&gt;&lt;br&gt;&lt;br&gt;(3) 执行代码，改变共享变量值 (use and assign)&lt;br&gt;&lt;br&gt;(4) 将工作内存数据刷回主存 (store and write)&lt;br&gt; &lt;br&gt;(5) 释放对象监视器的锁 (unlock)&lt;br&gt;&lt;br&gt;&lt;span style=&quot;color: rgb(255, 0, 0); &quot;&gt;注意: 其中4,5两步是同时进行的.&lt;/span&gt;&lt;br&gt;&lt;br&gt;这边最核心的就是第二步, 他同步了主内存,即前一个线程对变量改动的结果,可以被当前线程获知!(利用了happens-before ordering原则)&lt;br&gt;&lt;br&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;span&gt;对比之前的例子&lt;/span&gt;&lt;/strong&gt;&lt;br&gt; 如果多个线程同时执行一段未经锁保护的代码段，很有可能某条线程已经改动了变量的值，但是其他线程却无法看到这个改动，依然在旧的变量值上进行运算，最终导致不可预料的运算结果。&lt;br&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; &quot;&gt; &amp;nbsp;&lt;/p&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;hr style=&quot;height: 1px; margin-top: 1.5em; margin-right: 10px; margin-bottom: 1.5em; margin-left: 10px; border-bottom-color: black; border-bottom-width: thin; border-bottom-style: initial; &quot;&gt; &lt;/span&gt;&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; &quot;&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; &quot;&gt; &lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;br&gt;&lt;/strong&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;经典j2ee设计模式Double-Checked Locking失效问题&lt;/strong&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;双重检查锁定失效问题,一直是JMM无法避免的缺陷之一.了解DCL失效问题, 可以帮助我们深入JMM运行原理.&lt;br&gt; &lt;br&gt;要展示DCL失效问题, 首先要理解一个重要概念- 延迟加载(lazy loading).&lt;br&gt;&lt;br&gt;非单例的单线程延迟加载示例:&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;span class=&quot;f14&quot;&gt;class Foo&amp;nbsp;&lt;br&gt;{&lt;br&gt;private Resource res = null;&lt;br&gt;public Resource getResource()&amp;nbsp;&lt;br&gt; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 普通的延迟加载&lt;br&gt;if (res == null)&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; res = new Resource();&amp;nbsp;&lt;br&gt;return res;&lt;br&gt;}&lt;br&gt;}&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;非单例的&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;f14&quot;&gt;&lt;span style=&quot;font-size: small; &quot;&gt;多线程延迟加载示例:&lt;br&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;span class=&quot;f14&quot;&gt;Class Foo&amp;nbsp;&lt;br&gt;{&lt;br&gt;Private Resource res = null;&lt;br&gt;Public&amp;nbsp;&lt;span style=&quot;color: rgb(255, 0, 0); &quot;&gt;synchronized&lt;/span&gt;&amp;nbsp;Resource getResource()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; // 获取实例操作使用同步方式, 性能不高&lt;br&gt; If (res == null) res = new Resource();&lt;br&gt;return res;&lt;br&gt;}&lt;br&gt;}&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;非单例的&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;f14&quot;&gt;&lt;span style=&quot;font-size: small; &quot;&gt;DCL多线程延迟加载示例:&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;f14&quot;&gt;&lt;span style=&quot;font-size: small; &quot;&gt;Class Foo&amp;nbsp;&lt;br&gt; {&lt;br&gt;Private Resource res = null;&lt;br&gt;Public Resource getResource()&amp;nbsp;&lt;br&gt;{&lt;br&gt;If (res == null)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; //只有在第一次初始化时,才使用同步方式.&lt;br&gt;synchronized(this)&lt;br&gt;{&lt;br&gt;if(res == null)&lt;br&gt;{&lt;br&gt;res = new Resource();&lt;br&gt;}&lt;br&gt;}&lt;br&gt;}&lt;br&gt; return res;&lt;br&gt;}&lt;br&gt;}&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;f14&quot;&gt;&lt;span style=&quot;font-size: small; &quot;&gt;Double-Checked Locking看起来是非常完美的。但是很遗憾，根据Java的语言规范，上面的代码是不可靠的。&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;f14&quot;&gt;&lt;span style=&quot;font-size: small; &quot;&gt;出现上述问题, 最重要的2个原因如下:&lt;br&gt; 1, 编译器优化了程序指令, 以加快cpu处理速度.&lt;br&gt;2, 多核cpu动态调整指令顺序, 以加快并行运算能力.&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;span class=&quot;f14&quot;&gt;问题出现的顺序:&lt;br&gt;1, 线程A, 发现对象未实例化, 准备开始实例化&lt;br&gt;2, 由于编译器优化了程序指令, 允许对象在构造函数未调用完前, 将&lt;/span&gt;&lt;span class=&quot;f14&quot;&gt;共享变量的引用指向&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;f14&quot;&gt;&lt;span style=&quot;font-size: small; &quot;&gt;部分构造的对象, 虽然对象未完全实例化, 但已经不为null了.&lt;br&gt; 3, 线程B, 发现部分构造的对象已不是null, 则直接返回了该对象.&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&quot;f14&quot;&gt;&lt;span style=&quot;font-size: small; &quot;&gt;不过, 一些著名的开源框架, 包括jive,lenya等也都在使用DCL模式, 且未见一些极端异常.&lt;br&gt;说明, DCL失效问题的出现率还是比较低的.&lt;br&gt;接下来就是性能与稳定之间的选择了?&lt;br&gt;&lt;br&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;span&gt;DCL的替代&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;a name=&quot;code2&quot; style=&quot;color: rgb(16, 138, 198); text-decoration: underline; &quot;&gt;&lt;strong style=&quot;font-weight: bold; &quot;&gt;&lt;span style=&quot;text-decoration: underline; &quot;&gt;&lt;span style=&quot;font-size: small; color: rgb(16, 138, 198); &quot;&gt;Initialize-On-Demand&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;span class=&quot;f14&quot;&gt;:&lt;br&gt; &lt;br&gt;public class Foo {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 似有静态内部类, 只有当有引用时, 该类才会被装载&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private static class LazyFoo {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; public static Foo foo = new Foo();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static Foo getInstance() {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; return LazyFoo.foo;&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;}&lt;/span&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;f14&quot;&gt;&lt;br&gt;&lt;span style=&quot;font-size: small; &quot;&gt;维基百科的DCL解释:&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;f14&quot;&gt;&lt;span style=&quot;font-size: small; &quot;&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Double-checked_locking&quot;&gt;http://en.wikipedia.org/wiki/Double-checked_locking&lt;/a&gt;&lt;br&gt; &lt;br&gt;DCL的完美解决方案:&lt;br&gt;&lt;a href=&quot;http://www.theserverside.com/patterns/thread.tss?thread_id=39606&quot;&gt;http://www.theserverside.com/patterns/thread.tss?thread_id=39606&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/span&gt; </description><link>http://swinging-breeze.blogspot.com/2010/02/java-memory-model.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-1203634020765045713</guid><pubDate>Sat, 20 Feb 2010 06:45:00 +0000</pubDate><atom:updated>2010-02-19T22:45:35.571-08:00</atom:updated><title>[转]lockInterruptibly 和lock的区别</title><description>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; &quot;&gt;&lt;div class=&quot;blog_content&quot;&gt;转自：&lt;a href=&quot;http://lzmhehe.javaeye.com/blog/402053&quot;&gt;http://lzmhehe.javaeye.com/blog/402053&lt;/a&gt;&lt;/div&gt; &lt;div class=&quot;blog_content&quot;&gt;&lt;br&gt;&lt;/div&gt;&lt;div class=&quot;blog_content&quot;&gt;参考&amp;nbsp;&lt;br&gt;&lt;a href=&quot;http://gceclub.sun.com.cn/Java_Docs/html/zh_CN/api/java/util/concurrent/locks/ReentrantLock.html#lockInterruptibly()&quot;&gt;http://gceclub.sun.com.cn/Java_Docs/html/zh_CN/api/java/util/concurrent/locks/ReentrantLock.html#lockInterruptibly()&lt;/a&gt;；&amp;nbsp;&lt;br&gt; &lt;a href=&quot;http://tomboxfan.javaeye.com/blog/368270&quot;&gt;http://tomboxfan.javaeye.com/blog/368270&lt;/a&gt;；&amp;nbsp;&lt;br&gt;&lt;br&gt;lockInterruptibly 与 lock比较区别在于&amp;nbsp;&lt;br&gt;lockInterruptibly 优先考虑响应中断，而不是响应锁定的普通获取或重入获取&amp;nbsp;&lt;br&gt;&lt;div class=&quot;dp-highlighter&quot; style=&quot;font-family: Consolas, &amp;#39;Courier New&amp;#39;, Courier, mono; font-size: 12px; background-color: transparent; width: 694px; overflow-x: auto; overflow-y: auto; margin-left: 9px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; &quot;&gt; &lt;div class=&quot;bar&quot;&gt;&lt;div class=&quot;tools&quot; style=&quot;padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; text-align: left; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: black; font-weight: bold; &quot;&gt; Java代码&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;ol start=&quot;1&quot; class=&quot;dp-j&quot; style=&quot;font-size: 1em; line-height: 1.4em; margin-top: 0px; margin-right: 0px; margin-bottom: 1px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 2px; padding-left: 0px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(209, 215, 220); border-right-color: rgb(209, 215, 220); border-bottom-color: rgb(209, 215, 220); border-left-color: rgb(209, 215, 220); list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(43, 145, 175); &quot;&gt; &lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;package&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;test;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;java.util.concurrent.TimeUnit;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;java.util.concurrent.locks.Lock;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;java.util.concurrent.locks.ReentrantLock;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;TTTT&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;main(String[]&amp;nbsp;args){&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Thread&amp;nbsp;i1&amp;nbsp;=&amp;nbsp;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;Thread(&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;RunIt3());&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Thread&amp;nbsp;i2&amp;nbsp;=&amp;nbsp;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;Thread(&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;RunIt3());&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i1.start();&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i2.start();&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i2.interrupt();&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;RunIt3&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;implements&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;Runnable{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;Lock&amp;nbsp;lock&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;ReentrantLock();&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;run(){&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;try&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;comment&quot; style=&quot;color: rgb(0, 130, 0); &quot;&gt;//---------------------------------a&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lock.lock();&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;comment&quot; style=&quot;color: rgb(0, 130, 0); &quot;&gt;//lock.lockInterruptibly();&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(Thread.currentThread().getName()&amp;nbsp;+&amp;nbsp;&lt;span class=&quot;string&quot; style=&quot;color: blue; &quot;&gt;&amp;quot;&amp;nbsp;running&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;);&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TimeUnit.SECONDS.sleep(&lt;span class=&quot;number&quot; style=&quot;color: rgb(192, 0, 0); &quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;);&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lock.unlock();&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(Thread.currentThread().getName()&amp;nbsp;+&amp;nbsp;&lt;span class=&quot;string&quot; style=&quot;color: blue; &quot;&gt;&amp;quot;&amp;nbsp;finished&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;);&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;keyword&quot; style=&quot;color: rgb(127, 0, 85); font-weight: bold; &quot;&gt;catch&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;(InterruptedException&amp;nbsp;e){&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(Thread.currentThread().getName()&amp;nbsp;+&amp;nbsp;&lt;span class=&quot;string&quot; style=&quot;color: blue; &quot;&gt;&amp;quot;&amp;nbsp;interrupted&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: black; &quot;&gt;);&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(209, 215, 220); background-color: rgb(250, 250, 250); line-height: 18px; &quot;&gt; &lt;span style=&quot;color: black; &quot;&gt;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;如果a处 是lock.lock();&amp;nbsp;&lt;br&gt;输出&amp;nbsp;&lt;br&gt;Thread-0 running&amp;nbsp;&lt;br&gt;(这里休眠了20s)&amp;nbsp;&lt;br&gt;Thread-0 finished&amp;nbsp;&lt;br&gt;Thread-1 running&amp;nbsp;&lt;br&gt;Thread-1 interrupted&amp;nbsp;&lt;br&gt;&lt;br&gt;&lt;br&gt;============================&amp;nbsp;&lt;br&gt; &lt;br&gt;如果a处是lock.lockInterruptibly()&amp;nbsp;&lt;br&gt;Thread-0 running&amp;nbsp;&lt;br&gt;Thread-1 interrupted&amp;nbsp;&lt;br&gt;(这里休眠了20s)&amp;nbsp;&lt;br&gt;Thread-0 finished&amp;nbsp;&lt;br&gt;=========================&amp;nbsp;&lt;br&gt;&lt;br&gt;如果a处是lock.tryLock();&amp;nbsp;&lt;br&gt;&lt;br&gt;&lt;br&gt;Thread-1 running&amp;nbsp;&lt;br&gt;Thread-0 running&amp;nbsp;&lt;br&gt; (这里休眠了20s)&amp;nbsp;&lt;br&gt;Thread-1 finished&amp;nbsp;&lt;br&gt;Exception in thread &amp;quot;Thread-0&amp;quot; java.lang.IllegalMonitorStateException&amp;nbsp;&lt;br&gt;at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(Unknown Source)&amp;nbsp;&lt;br&gt;at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(Unknown Source)&amp;nbsp;&lt;br&gt; at java.util.concurrent.locks.ReentrantLock.unlock(Unknown Source)&amp;nbsp;&lt;br&gt;at test.RunIt3.run(TTTT.java:32)&amp;nbsp;&lt;br&gt;at java.lang.Thread.run(Unknown Source)&amp;nbsp;&lt;br&gt;&lt;br&gt;&lt;br&gt;=========================&amp;nbsp;&lt;br&gt;&lt;br&gt;如果a处是lock.tryLock(10,TimeUnit.SECONDS);&amp;nbsp;&lt;br&gt; &lt;br&gt;Thread-0 running&amp;nbsp;&lt;br&gt;(这里休眠了10s)&amp;nbsp;&lt;br&gt;Thread-1 running&amp;nbsp;&lt;br&gt;&lt;br&gt;(这里休眠了10s)&amp;nbsp;&lt;br&gt;Thread-0 finished&amp;nbsp;&lt;br&gt;(这里休眠了10s)&amp;nbsp;&lt;br&gt;Exception in thread &amp;quot;Thread-1&amp;quot; java.lang.IllegalMonitorStateException&amp;nbsp;&lt;br&gt;at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(Unknown Source)&amp;nbsp;&lt;br&gt; at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(Unknown Source)&amp;nbsp;&lt;br&gt;at java.util.concurrent.locks.ReentrantLock.unlock(Unknown Source)&amp;nbsp;&lt;br&gt;at test.RunIt3.run(TTTT.java:32)&amp;nbsp;&lt;br&gt;at java.lang.Thread.run(Unknown Source)&amp;nbsp;&lt;br&gt; &lt;/div&gt;&lt;ins style=&quot;display: inline-table; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; height: 60px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; position: relative; visibility: visible; width: 468px; &quot;&gt;&lt;/ins&gt;&lt;/span&gt; </description><link>http://swinging-breeze.blogspot.com/2010/02/lockinterruptibly-lock.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-1480544981218820298</guid><pubDate>Tue, 16 Feb 2010 05:50:00 +0000</pubDate><atom:updated>2010-02-15T21:50:40.414-08:00</atom:updated><title>[转][精品]在Java中使用协程</title><description>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &amp;#39;Lucida Grande&amp;#39;, Verdana, Arial, sans-serif; font-size: 13px; color: rgb(51, 51, 51); line-height: 19px; &quot;&gt;&lt;h2 style=&quot;margin-top: 10px; font-size: 1.1em; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;转自：&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px; &quot;&gt;&lt;a href=&quot;http://www.blogjava.net/BlueDavy/archive/2010/01/28/311148.html&quot;&gt;http://www.blogjava.net/BlueDavy/archive/2010/01/28/311148.html&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt; &lt;h2 style=&quot;margin-top: 10px; font-size: 1.1em; &quot;&gt;&lt;br&gt;&lt;/h2&gt;&lt;h2 style=&quot;margin-top: 10px; font-size: 1.1em; &quot;&gt;&lt;a id=&quot;viewpost1_TitleUrl&quot; href=&quot;http://www.blogjava.net/BlueDavy/archive/2010/01/28/311148.html&quot; style=&quot;color: rgb(0, 102, 255); text-decoration: none; &quot;&gt;在Java中使用协程（Coroutine）&lt;/a&gt;&lt;/h2&gt; &lt;div class=&quot;postText&quot; style=&quot;font-size: 10pt; line-height: 19px; padding-left: 5px; &quot;&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;本篇blog将讲述coroutine的一些背景知识，以及在Java中如何使用Coroutine，包括一个简单的benchmark对比，希望能借助这篇blog让大家了解到更多在java中使用coroutine的方法，本篇blog的PDF版本可从此下载：&lt;a href=&quot;http://www.bluedavy.com/open/UseCoroutineInJava.pdf&quot; target=&quot;_blank&quot; style=&quot;color: rgb(0, 102, 255); text-decoration: none; &quot;&gt;http://www.bluedavy.com/open/UseCoroutineInJava.pdf&lt;/a&gt;&lt;br&gt; 在讲到具体内容之前，不能不先讲下&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的一些背景知识，来先具体了解下什么是&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;。&lt;/span&gt;&lt;/p&gt;&lt;h1 style=&quot;font-size: 1.5em; color: rgb(0, 0, 0); padding-left: 100px; height: 20px; margin-top: 6pt; margin-right: 0cm; margin-bottom: 6pt; margin-left: 21pt; padding-bottom: 30px; font-family: &amp;#39;Courier New&amp;#39;, Verdana, monospace; text-align: left; text-indent: -21pt; &quot;&gt; &lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 14pt; line-height: 45px; font-weight: normal; &quot;&gt;&lt;span&gt;1.&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 14pt; line-height: 45px; font-family: 宋体; &quot;&gt;背景知识&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 14pt; line-height: 45px; font-weight: normal; &quot;&gt;&lt;/span&gt;&lt;/h1&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;现在的操作系统都是支持多任务的，多任务可通过多进程或多线程的方式去实现，进程和线程的对比就不在这里说了，在多任务的调度上操作系统采取抢占式和协作式两种方式，抢占式是指操作系统给每个任务一定的执行时间片，在到达这个时间片后如任务仍然未释放对&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;CPU&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的占用，那么操作系统将强制释放，这是目前多数操作系统采取的方式；协作式是指操作系统按照任务的顺序来分配&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;CPU&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，每个任务执行过程中除非其主动释放，否则将一直占据&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;CPU&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，这种方式非常值得注意的是一旦有任务占据&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;CPU&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;不放，会导致其他任务&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&amp;rdquo;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;饿死&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&amp;rdquo;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的现象，因此操作系统确实不太适合采用这种方式。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;说完操作系统多任务的调度方式后，来看看通常程序是如何实现支持高并发的，一种就是典型的基于操作系统提供的多进程或多线程机制，每个任务占据一个进程或一个线程，当任务中有&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;IO&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;等待等动作时，则将进程或线程放入待调度队列中，这种方式是目前大多数程序采取的方式，这种方式的坏处在于如想支持高的并发量，就不得不创建很多的进程或线程，而进程和线程都是要消耗不少系统资源的，另外一方面，进程或线程创建太多后，操作系统需要花费很多的时间在进程或线程的切换上，切换动作需要做状态保持和恢复，这也会消耗掉很多的系统资源；另外一种方式则是每个任务不完全占据一个进程或线程，当任务执行过程中需要进行&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;IO&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;等待等动作时，任务则将其所占据的进程或线程释放，以便其他任务使用这个进程或线程，这种方式的好处在于可以减少所需要的原生的进程或线程数，并且由于操作系统不需要做进程或线程的切换，而是自行来实现任务的切换，其成本会较操作系统切换低，这种方式也就是本文的重点，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方式，又称协程方式，这种方式在目前的大多数语言中都有支持。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;各种语言在实现&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方式的支持时，多数都采用了&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor Model&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;来实现，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor Model&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;简单来说就是每个任务就是一个&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;之间通过消息传递的方式来进行交互，而不采用共享的方式，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;可以看做是一个轻量级的进程或线程，通常在一台&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;4G&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;内存的机器上，创建几十万个&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;是毫无问题的，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;支持&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Continuations&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，即对于如下代码：&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;Actor&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;act&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方法&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;进行一些处理&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span style=&quot;font-family: 宋体; &quot;&gt;创建并执行另外一个&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;通过消息&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;box&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;阻塞获取另一个&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;执行的结果&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;继续基于这个结果进行一些处理&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;在支持&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Continuations&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的情况下，可以做到消息&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;box&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;阻塞时并不是进程或线程级的阻塞，而只是&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;本身的阻塞，并且在阻塞时可将所占据的进程或线程释放给其他&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;使用，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor Model&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;实现最典型的就是&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;erLang&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;了。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;对于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;应用而言，传统方式下为了支持高并发，由于一个线程只能用于处理一个请求，即使是线程中其实有很多&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;IO&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中断、锁等待也同样如此，因此通常的做法是通过启动很多的线程来支撑高并发，但当线程过多时，就造成了&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;CPU&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;需要消耗不少的时间在线程的切换上，从而出现瓶颈，按照上面对&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的描述，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的方式理论上而言能够大幅度的提升&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;应用所能支撑的并发量。&lt;/span&gt;&lt;/p&gt; &lt;h1 style=&quot;font-size: 1.5em; color: rgb(0, 0, 0); padding-left: 100px; height: 20px; margin-top: 6pt; margin-right: 0cm; margin-bottom: 6pt; margin-left: 21pt; padding-bottom: 30px; font-family: &amp;#39;Courier New&amp;#39;, Verdana, monospace; text-align: left; text-indent: -21pt; &quot;&gt; &lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 14pt; line-height: 45px; &quot;&gt;&lt;span&gt;2.&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 14pt; line-height: 45px; font-family: 宋体; &quot;&gt;在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 14pt; line-height: 45px; &quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-size: 14pt; line-height: 45px; font-family: 宋体; &quot;&gt;中使用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 14pt; line-height: 45px; &quot;&gt;Coroutine&lt;/span&gt;&lt;/h1&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;尚不能从语言层次上支持&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，也许&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java 7&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;能够支持，目前已经有了一个测试性质的版本&lt;/span&gt;&lt;a href=&quot;file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/%E5%9C%A8Java%E4%B8%AD%E4%BD%BF%E7%94%A8Coroutine.docx#_ftn1&quot; name=&quot;_ftnref1&quot; title=&quot;&quot; style=&quot;color: rgb(0, 102, 255); text-decoration: none; &quot;&gt;&lt;span class=&quot;MsoFootnoteReference&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&lt;span class=&quot;MsoFootnoteReference&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 10.5pt; font-family: Calibri, sans-serif; &quot;&gt;[1]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Sun JDK 7&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;尚未正式发布的情况下如希望在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中使用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;或&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;是可以做的选择，来分别看下。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;是现在很火的语言之一，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Twitter&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;消息中间件基于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;编写更是让&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;名声鹊起，除了在语法方面所做出的改进外，其中一个最突出的特色就是&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;是&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;用于实现&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的方式，先来具体看看&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;支持实现的关键概念。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;可以看做是一个轻量级的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java Thread&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，其使用方式和&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java Thread&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;基本也一致，继承&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，实现&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;act&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方法，启动时也是调用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;start&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方法，但和&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java Thread&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;不同的是，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;可等待外部发送过来的消息，并进行相应的处理。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的消息发送机制&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;发送消息到&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的方式有异步、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Future&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;两种方式，异步即指发送后立即返回，继续后续流程，使用异步发送的方法为：&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;actor ! MessageObject&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，其中消息对象可以为任何类型，并且&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;还支持一种称为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;case Object&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的对象，便于在收到消息时做&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;pattern matching&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;Future&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方式是指阻塞线程等待消息处理的结果，使用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Future&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方式发送的方法为：&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;actor !! MessageObject&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，在等待结果方面，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;支持不限时等待，限时等待以及等待多个&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Future&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;或个别&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Future&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;完成，使用方法如下：&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;val ft=actor !! MessageObject // Future&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方式发送消息&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;val result=ft() //&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;不限时等待&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;val results=awaitAll(500,ft1,ft2,ft3)&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;//&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;限时等待多个&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Future&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;返回值&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;val results=awaitEither(ft1,ft2) //&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;等待个别&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;future&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;完成&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;接收消息方通过&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;reply&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方法返回&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Future&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方式所等待的结果。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的消息接收机制&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;当代码处于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;act&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方法或&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;环境（例如为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;act&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方法调用过来的代码）中时，可通过以下两种方式来接收外部发送给&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的消息：一为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;receive&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方式，二为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;react&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方式，代码例子如下：&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;receive{&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;case MessageObject(args) =&amp;gt; doHandle(args)&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;react{&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;case MessageObject(args) =&amp;gt; doHandle(args)&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;receive&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;和&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;react&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的差别在于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;receive&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;需要阻塞当前&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;线程，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;react&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;则仅为阻塞当前&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，但并不会阻塞&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;线程，因此&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;react&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;模式更适合于充分发挥&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;带来的原生线程数减少的好处，但&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;react&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;模式有个缺点是&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;react&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;不支持返回。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;receive&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;和&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;react&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;都有限时接收的方式，方法为：&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;receiveWithin(timeout)&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;reactWithin(timeout)&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，超时的消息通过&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;case TIMEOUT&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的方式来接收。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;下面来看基于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;实现并发处理请求的一个简单例子。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;class Processor extends Actor{&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;def act(){&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;loop{&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;react{&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;case command:String =&amp;gt; doHandle(command)&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 63pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;def doHandle(command:String){&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;//&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;业务逻辑处理&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;当需要并发执行此&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Processor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;时，在处理时需要的仅为调用以下代码：&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;val processor=new Processor()&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;processor.start&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;processor ! &amp;ldquo;Hello&amp;rdquo;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;从以上说明来看，要在旧的应用中使用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;还是会有一些成本，部署运行则非常简单，在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala IDE Plugin&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;编写了上面的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;代码后，即生成了&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;java class&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;文件，可直接在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;jvm&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中运行。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;是由剑桥的两位博士开发的一个用于在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中使用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的框架，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;基于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;语法，先来看看&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中的关键概念。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;可以认为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;就是&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，使用方式和&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java Thread&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;基本相同，只是继承的为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，覆盖的为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;execute&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方法，启动也是调用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;task&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;start&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方法。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的消息发送机制&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中通过&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Mailbox&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;对象来发送消息，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Mailbox&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的基本原则为可以有多个消息发送者，但只能有一个消息接收者，发送的方式有同步发送、异步发送和阻塞线程方式的同步发送三种，同步发送是指保证一定能将消息放入发送队列中，如当前发送队列已满，则等待到可用为止，阻塞的为当前&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;；异步发送则是尝试将消息放入发送队列一次，如失败，则返回&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，成功则返回&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，不会阻塞&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;；阻塞线程方式的同步发送是指阻塞当前线程，并保证将消息发送给接收者，三种方式的使用方法如下：&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;mailbox.put(messageObject); //&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;同步发送&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;mailbox.putnb(messageObject); //&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;异步发送&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;mailbox.putb(messageObject); //&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;阻塞线程方式发送&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的消息接收机制&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中通过&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Mailbox&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;来接收消息，接收消息的方式有同步接收、异步接收以及阻塞线程方式的同步接收三种，同步接收是指阻塞当前&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，直到接收到消息才返回；异步接收是指立刻返回&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Mailbox&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中的消息，有就返回，没有则返回&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;；阻塞线程方式的同步接收是指阻塞当前线程，直到接收到消息才返回，使用方法如下：&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;mailbox.get(); //&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;同步接收，传入&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;long&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;参数表示等待的超时时间，单位为毫秒&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;mailbox.getnb(); //&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;异步接收，立刻返回&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;mailbox.getb(); //&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;阻塞线程方式接收&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;下面来看基于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;实现并发处理请求的一个简单例子。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;public class Processor extends Task{&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;private String command;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;public Processor(String command){&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;this.command=command;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;public void execute() throws Pausable,Exception{&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;//&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;业务逻辑处理&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;在处理时，仅需调用以下代码：&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task processor=new Processor(command);&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;processor.start();&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;从以上代码来看，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;对于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;人员而言学习门槛更低，但对于需要采用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方式执行的代码在编译完毕后，还需要采用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;kilim.tools.Weaver&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;类来对这些已编译出来的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;文件做织入，运行时需要用织入后生成的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;文件才行，织入的方法为：&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;java kilim.tools.Weaver &amp;ndash;d [&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;织入后生成的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;文件存放的目录&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;] [&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;需要织入的类文件所在的目录&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，目前尚没有&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim IDE Plugin&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;可用，因此&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;weaver&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;这个过程还是比较的麻烦。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;上面对&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;和&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;做了一个简单的介绍，在实际&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;应用中使用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;时，通常会出现以下几种典型的更复杂的使用场景，由于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;模式本身就是异步的，因此其天然对异步场景支持的就非常好，更多的问题会出现在以下几个同步场景上，分别来看看基于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;如何来实现。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;同步调用&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;同步调用是经常会出现的使用场景，主要为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;发送消息给其他的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;处理，并等待结果才能继续。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 63pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;n&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;对于这种情况，在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala 2.7.7&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中，目前可采取的为以下两种方法：&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;一种为通过&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Future&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方式发送消息来实现：&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;class Processor(command:String) extends Actor{&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;def act(){&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;val actor=new NetSenderActor()&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;val ft=actor !! command&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;println(ft())&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;class NetSenderActor extends Actor{&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;def act(){&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;case command:String =&amp;gt; {&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;reply(&amp;ldquo;received command:&amp;rdquo;+command)&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 63pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span style=&quot;font-family: 宋体; &quot;&gt;第二种为通过&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;receive&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的方式来实现：&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;class Processor(command:String) extends Actor{&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;def act(){&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;val actor=new NetSenderActor()&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;actor ! command&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;var senderResult=&amp;rdquo;&amp;rdquo;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 63pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;receive{&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;case result:String =&amp;gt; {&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 105pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;senderResult=result&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 84pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 63pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 63pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;println(senderResult)&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;class NetSenderActor extends Actor{&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;def act(){&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;case command:String =&amp;gt; {&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;sender ! (&amp;ldquo;received command:&amp;rdquo;+command)&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 63pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span style=&quot;font-family: 宋体; &quot;&gt;但这两种方式其实都不好，因为这两种方式都会造成当前&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的线程阻塞，这也是因为目前&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;版本对&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;continuations&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;尚不支持的原因，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala 2.8&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;版本将提供&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;continuations&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的支持，希望到时能有不需要阻塞&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;线程实现上述需求的方法。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;还有一种常见的场景是&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;调一段普通的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;类，然后那个类中进行了一些处理，并调用了其他&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，此时在该类中如需要等待&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的返回结果，也可使用上面两种方法。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 63pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;n&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中要实现&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;之间的同步调用非常简单，代码如下：&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;public class TaskA extends Task{&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;public void execute() throws Pausable,Exception{&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;Mailbox&amp;lt;Object&amp;gt; result=new Mailbox&amp;lt;Object&amp;gt;();&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 63pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;Task task=new TaskB(result);&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;task.start();&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;Object resultObject=result.get();&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;System.out.println(resultObject);&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;public class TaskB extends Task{&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;private Mailbox&amp;lt;Object&amp;gt; result;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;public TaskB(Mailbox&amp;lt;Object&amp;gt; result){&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;this.result=result;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;public void execute() throws Pausable,Exception{&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;result.put(&amp;ldquo;result from TaskB&amp;rdquo;);&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Mailbox.get&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;并不会阻塞线程，因此这种方式是完全满足需求的。&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;普通&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;代码同步调用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;由于已有的应用是普通的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;代码，经常会出现这样的场景，就是希望实现在这些&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;代码中同步的调用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，并等待&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的返回结果，但由于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;和&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;都强调首先必须是在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;或&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的环境下才行，因此此场景更佳的方式应为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala Actor(Kilim Task)&amp;nbsp;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;à&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&amp;nbsp;Java Code&amp;nbsp;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;à&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&amp;nbsp;Scala Actor(Kilim Task)&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，这种场景在对已有的应用中会是最常出现的，来看看在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;和&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中如何应对这样的需求。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 63pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;n&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;目前&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中如希望在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java Code&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中调用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，并等待其返回结果，暂时还没办法，做法只能改为从&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java Code&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中去调一个&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Object&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，然后在这个&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Object&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中调用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Actor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，并借助上面提到的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;receive&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;或&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;future&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的方法来获取返回值，最后将这个返回值返回&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java Code&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 63pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;n&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;目前&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中如希望实现上面的需求，其实非常简单，只需要在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java Code&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的方法上加上&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Throw Pausable&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，然后通过&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mailbox.get&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;来等待&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim Task&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;返回的结果即可，在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中只要调用栈上的每个方法都有&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Throw Pausable&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，就可在这些方法上做等待返回这类的同步操作。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;从上面这两个最常见的需求来看，无疑&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;更符合需求，但要注意的是对于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;而言，如果出现&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task&amp;nbsp;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;à&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&amp;nbsp;nonpausable method&amp;nbsp;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;à&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&amp;nbsp;pausable method&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;这样的状况时，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;pausable method&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中如果想执行阻塞当前&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的操作，是无法做到的，只能改造成&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task (&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mailbox&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;上做等待，并传递&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mailbox&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;给后续步骤&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;)&amp;nbsp;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;à&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&amp;nbsp;nonpausable method (&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;传递&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mailbox)&amp;nbsp;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;à&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;pausable method (&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;将逻辑转为放入一个&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Task&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中，并将返回值放入传递过来的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mailbox)&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，这种状况在面对&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;spring aop&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;、反射调用等现象时就会出现了，目前&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;kilim 0.6&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的版本尚未提供更透明的使用方法，不过据&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;作者提供的一个试用版本，其中已经有了对于反射调用的透明化的支持，暂时在目前只能采用上述方法，迁移成本相对较大，也许以后的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;版本会考虑这样的场景，提供相应的方法来降低迁移的成本。&lt;/span&gt;&lt;/p&gt; &lt;h1 style=&quot;font-size: 1.5em; color: rgb(0, 0, 0); padding-left: 100px; height: 20px; margin-top: 6pt; margin-right: 0cm; margin-bottom: 6pt; margin-left: 21pt; padding-bottom: 30px; font-family: &amp;#39;Courier New&amp;#39;, Verdana, monospace; text-align: left; text-indent: -21pt; &quot;&gt; &lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 14pt; line-height: 45px; &quot;&gt;&lt;span&gt;3.&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 14pt; line-height: 45px; font-family: 宋体; &quot;&gt;性能、所能支撑的并发量对比&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 14pt; line-height: 45px; &quot;&gt;&lt;/span&gt;&lt;/h1&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;在对&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;有了这些了解后，来具体看看采用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;后与传统&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方式在性能、所能支撑的并发量上的对比。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;测试模型&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;采用一个比较简单的模型进行测试，具体为有&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;个线程，这&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;个线程分别接收到了一定数量的请求，每个请求需要交给另外一个线程去执行，这个线程所做的动作为循环&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;次获取另外一个线程的执行结果，此执行线程所做的动作为循环&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;次拼接一个字符串，然后返回。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;实现代码&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;由于目前&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;版本对&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Continuation&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;支持不够好，但上面的场景中又有此类需求，所以导致&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;版本的代码写的比较麻烦一些。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;实现代码以及可运行的环境请从此处下载：&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20pt; line-height: 19px; &quot;&gt; &lt;span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 10pt; line-height: 19px; font-family: Arial, sans-serif; color: rgb(0, 136, 0); &quot;&gt;&lt;a href=&quot;http://www.bluedavy.com/open/benchmark.zip&quot;&gt;http://www.bluedavy.com/open/benchmark.zip&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 42pt; text-align: left; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Wingdings; &quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;结果对比&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;测试机器为一台&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;核的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;linux&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;机器。&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;TPS&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的对比结果如下：&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;img src=&quot;http://bluedavy.com/wp-content/uploads/2010/01/tps.PNG&quot; width=&quot;491&quot; height=&quot;294&quot; alt=&quot;&quot;&gt;&lt;br&gt; &amp;nbsp;&amp;nbsp; &amp;nbsp;Load&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的对比结果如下：&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;img src=&quot;http://bluedavy.com/wp-content/uploads/2010/01/load.PNG&quot; width=&quot;491&quot; height=&quot;294&quot; alt=&quot;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt; &lt;span lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;从上面的测试结果来看，在这个&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;benchmark&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的场景中，基于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;和&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;实现的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;版本在随着请求数增长的情况下&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;load&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的增长幅度都比纯粹的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;版本低很多，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Kilim&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;版本表现尤其突出，在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;TPS&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方面，由于目前&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Scala&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;版本对&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Continuation&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;支持的不好，因此在这个测试场景中有点吃亏，表现反而最差，经过上面的测试可以看到，基于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;版本可以以同样的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;load&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;或更低的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;load&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;来支撑更高的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;TPS&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; align=&quot;left&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; text-indent: 21pt; line-height: 19px; &quot;&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;到此为止，基本上对&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中使用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;的相关知识做了一个介绍，总结而言，采用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方式可以很好的绕开需要启动太多线程来支撑高并发出现的瓶颈，提高&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;应用所能支撑的并发量，但在开发模式上也会带来变化，并且需要特别注意不能造成线程被阻塞的现象，从开发易用和透明迁移现有&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;应用两个角度而言目前&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;方式还有很多不足，但相信随着越来越多的人在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Java&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;中使用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Coroutine&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; &quot;&gt;，其易用性必然是能够得到提升的。&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;br clear=&quot;all&quot; style=&quot;page-break-before: always; &quot;&gt; &lt;/span&gt;&lt;/p&gt;&lt;h1 style=&quot;font-size: 1.5em; color: rgb(0, 0, 0); padding-left: 100px; height: 20px; margin-top: 6pt; margin-right: 0cm; margin-bottom: 6pt; margin-left: 21pt; padding-bottom: 30px; font-family: &amp;#39;Courier New&amp;#39;, Verdana, monospace; text-align: left; text-indent: -21pt; &quot;&gt; &lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 14pt; line-height: 45px; &quot;&gt;&lt;span&gt;4.&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 14pt; line-height: 45px; font-family: 宋体; &quot;&gt;参考资料&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 14pt; line-height: 45px; &quot;&gt;&lt;/span&gt;&lt;/h1&gt; &lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;1.&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Computer_multitasking&quot; style=&quot;color: rgb(0, 102, 255); text-decoration: none; &quot;&gt;http://en.wikipedia.org/wiki/Computer_multitasking&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;2.&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Coroutine&quot; style=&quot;color: rgb(0, 102, 255); text-decoration: none; &quot;&gt;http://en.wikipedia.org/wiki/Coroutine&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;3.&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Actor_model&quot; style=&quot;color: rgb(0, 102, 255); text-decoration: none; &quot;&gt;http://en.wikipedia.org/wiki/Actor_model&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;4.&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Continuation&quot; style=&quot;color: rgb(0, 102, 255); text-decoration: none; &quot;&gt;http://en.wikipedia.org/wiki/Continuation&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;5.&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;a href=&quot;http://lamp.epfl.ch/~phaller/doc/haller07coord.pdf&quot; style=&quot;color: rgb(0, 102, 255); text-decoration: none; &quot;&gt;http://lamp.epfl.ch/~phaller/doc/haller07coord.pdf&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;6.&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;a href=&quot;http://www.scala-lang.org/sites/default/files/odersky/jmlc06.pdf&quot; style=&quot;color: rgb(0, 102, 255); text-decoration: none; &quot;&gt;http://www.scala-lang.org/sites/default/files/odersky/jmlc06.pdf&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;7.&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;a href=&quot;http://www.malhar.net/sriram/kilim/kilim_ecoop08.pdf&quot; style=&quot;color: rgb(0, 102, 255); text-decoration: none; &quot;&gt;http://www.malhar.net/sriram/kilim/kilim_ecoop08.pdf&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 21pt; text-indent: -21pt; line-height: 19px; &quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;8.&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;; &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;a href=&quot;http://lamp.epfl.ch/~phaller/doc/ScalaActors.pdf&quot; style=&quot;color: rgb(0, 102, 255); text-decoration: none; &quot;&gt;http://lamp.epfl.ch/~phaller/doc/ScalaActors.pdf&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;div&gt;&lt;br clear=&quot;all&quot;&gt;&lt;hr align=&quot;left&quot; size=&quot;1&quot; width=&quot;33%&quot;&gt;&lt;div id=&quot;ftn1&quot;&gt;&lt;p class=&quot;MsoFootnoteText&quot; style=&quot;margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; &quot;&gt;&lt;a href=&quot;file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/%E5%9C%A8Java%E4%B8%AD%E4%BD%BF%E7%94%A8Coroutine.docx#_ftnref1&quot; name=&quot;_ftn1&quot; title=&quot;&quot; style=&quot;color: rgb(0, 102, 255); text-decoration: none; &quot;&gt;&lt;span class=&quot;MsoFootnoteReference&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;&lt;span class=&quot;MsoFootnoteReference&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9pt; font-family: Calibri, sans-serif; &quot;&gt;[1]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span lang=&quot;EN-US&quot;&gt;&amp;nbsp;&lt;a href=&quot;http://weblogs.java.net/blog/forax/archive/2009/11/19/holy-crap-jvm-has-coroutinecontinuationfiber-etc&quot; style=&quot;color: rgb(0, 102, 255); text-decoration: none; &quot;&gt;http://weblogs.java.net/blog/forax/archive/2009/11/19/holy-crap-jvm-has-coroutinecontinuationfiber-etc&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt; </description><link>http://swinging-breeze.blogspot.com/2010/02/java.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3345672455004235930.post-707760119331872483</guid><pubDate>Mon, 15 Feb 2010 15:14:00 +0000</pubDate><atom:updated>2010-02-15T07:21:05.639-08:00</atom:updated><title>[转][精品]布隆过滤器(Bloom Filter)</title><description>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, arial; font-size: 13px; line-height: 20px; &quot;&gt;&lt;div&gt;转自：&lt;a href=&quot;http://googlechinablog.com/2007/07/bloom-filter.html&quot;&gt;http://googlechinablog.com/2007/07/bloom-filter.html&lt;/a&gt;&lt;/div&gt; &lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;a href=&quot;http://www.blogjava.net/stone2083/archive/2010/01/30/311329.html&quot;&gt;http://www.blogjava.net/stone2083/archive/2010/01/30/311329.html&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;在日常生活中，包括在设计计算机软件时，我们经常要判断一个元素是否在一个集合中。比如在字处理软件中，需要检查一个英语单词是否拼写正确（也就是要判断它是否在已知的字典中）；在 FBI，一个嫌疑人的名字是否已经在嫌疑名单上；在网络爬虫里，一个网址是否被访问过等等。最直接的方法就是将集合中全部的元素存在计算机中，遇到一个新元素时，将它和集合中的元素直接比较即可。一般来讲，计算机中的集合是用哈希表（hash table）来存储的。它的好处是快速准确，缺点是费存储空间。当集合比较小时，这个问题不显著，但是当集合巨大时，哈希表存储效率低的问题就显现出来了。比如说，一个象 Yahoo,Hotmail 和 Gmai 那样的公众电子邮件（email）提供商，总是需要过滤来自发送垃圾邮件的人（spamer）的垃圾邮件。一个办法就是记录下那些发垃圾邮件的 email 地址。由于那些发送者不停地在注册新的地址，全世界少说也有几十亿个发垃圾邮件的地址，将他们都存起来则需要大量的网络服务器。如果用哈希表，每存储一亿个 email 地址， 就需要 1.6GB 的内存（用哈希表实现的具体办法是将每一个 email 地址对应成一个八字节的信息指纹&lt;a target=&quot;_blank&quot; href=&quot;http://googlechinablog.com/2006/08/blog-post.html&quot;&gt;googlechinablog.com/2006/08/blog-post.html&lt;/a&gt;，然后将这些信息指纹存入哈希表，由于哈希表的存储效率一般只有 50%，因此一个 email 地址需要占用十六个字节。一亿个地址大约要 1.6GB， 即十六亿字节的内存）。因此存贮几十亿个邮件地址可能需要上百 GB 的内存。除非是超级计算机，一般服务器是无法存储的。&lt;br&gt; &lt;br&gt;今天，我们介绍一种称作布隆过滤器的数学工具，它只需要哈希表 1/8 到 1/4 的大小就能解决同样的问题。&lt;br&gt;&lt;br&gt;布隆过滤器是由巴顿.布隆于一九七零年提出的。它实际上是一个很长的二进制向量和一系列随机映射函数。我们通过上面的例子来说明起工作原理。&lt;br&gt;&lt;br&gt;假定我们存储一亿个电子邮件地址，我们先建立一个十六亿二进制（比特），即两亿字节的向量，然后将这十六亿个二进制全部设置为零。对于每一个电子邮件地址 X，我们用八个不同的随机数产生器（F1,F2, ...,F8） 产生八个信息指纹（f1, f2, ..., f8）。再用一个随机数产生器 G 把这八个信息指纹映射到 1 到十六亿中的八个自然数 g1, g2, ...,g8。现在我们把这八个位置的二进制全部设置为一。当我们对这一亿个 email 地址都进行这样的处理后。一个针对这些 email 地址的布隆过滤器就建成了。（见下图）&lt;br&gt; &lt;br&gt;&lt;img src=&quot;http://googlechinablog.com/uploaded_images/bloomfilter-730334.jpg&quot; border=&quot;0&quot; alt=&quot;&quot; style=&quot;clear: both; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: grey; border-right-color: grey; border-bottom-color: grey; border-left-color: grey; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; &quot;&gt;&lt;br&gt; &lt;br&gt;现在，让我们看看如何用布隆过滤器来检测一个可疑的电子邮件地址 Y 是否在黑名单中。我们用相同的八个随机数产生器（F1, F2, ..., F8）对这个地址产生八个信息指纹 s1,s2,...,s8，然后将这八个指纹对应到布隆过滤器的八个二进制位，分别是 t1,t2,...,t8。如果 Y 在黑名单中，显然，t1,t2,..,t8 对应的八个二进制一定是一。这样在遇到任何在黑名单中的电子邮件地址，我们都能准确地发现。&lt;br&gt;&lt;br&gt; 布隆过滤器决不会漏掉任何一个在黑名单中的可疑地址。但是，它有一条不足之处。也就是它有极小的可能将一个不在黑名单中的电子邮件地址判定为在黑名单中，因为有可能某个好的邮件地址正巧对应个八个都被设置成一的二进制位。好在这种可能性很小。我们把它称为误识概率。在上面的例子中，误识概率在万分之一以下。&amp;nbsp;&lt;br&gt;&lt;br&gt;布隆过滤器的好处在于快速，省空间。但是有一定的误识别率。常见的补救办法是在建立一个小的白名单，存储那些可能别误判的邮件地址。&lt;/span&gt;&lt;div&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, arial; font-size: 13px; line-height: 20px; &quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, arial; font-size: 13px; line-height: 20px; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: palatino, georgia, verdana, arial, sans-serif; line-height: 21px; font-size: 14px; &quot;&gt;BloomFilter简易实现：&lt;br&gt; &lt;div style=&quot;border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); padding-top: 4px; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 1002px; &quot;&gt; &lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;SimpleBloomFilter&amp;nbsp;{&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;final&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;DEFAULT_SIZE&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;24&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;;&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;final&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;[]&amp;nbsp;seeds&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;[]&amp;nbsp;{&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;11&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;31&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;37&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;61&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;,&amp;nbsp;};&lt;br&gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;BitSet&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bits&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;BitSet(DEFAULT_SIZE);&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;SimpleHash[]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;func&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;SimpleHash[seeds.length];&lt;br&gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;main(String[]&amp;nbsp;args)&amp;nbsp;{&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String&amp;nbsp;value&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&lt;a href=&quot;mailto:stone2083@yahoo.cn&quot;&gt;stone2083@yahoo.cn&lt;/a&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;;&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SimpleBloomFilter&amp;nbsp;filter&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;SimpleBloomFilter();&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(filter.contains(value));&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;filter.add(value);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(filter.contains(value));&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;SimpleBloomFilter()&amp;nbsp;{&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;i&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;;&amp;nbsp;i&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;seeds.length;&amp;nbsp;i&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;)&amp;nbsp;{&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;func[i]&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;SimpleHash(DEFAULT_SIZE,&amp;nbsp;seeds[i]);&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;add(String&amp;nbsp;value)&amp;nbsp;{&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;(SimpleHash&amp;nbsp;f&amp;nbsp;:&amp;nbsp;func)&amp;nbsp;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bits.set(f.hash(value),&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;);&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;boolean&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;contains(String&amp;nbsp;value)&amp;nbsp;{&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;(value&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;)&amp;nbsp;{&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;boolean&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;ret&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;;&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;(SimpleHash&amp;nbsp;f&amp;nbsp;:&amp;nbsp;func)&amp;nbsp;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ret&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;ret&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;bits.get(f.hash(value));&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;ret;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;SimpleHash&amp;nbsp;{&lt;br&gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;cap;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;seed;&lt;br&gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;SimpleHash(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;cap,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;seed)&amp;nbsp;{&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;.cap&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;cap;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;.seed&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;seed;&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;hash(String&amp;nbsp;value)&amp;nbsp;{&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;result&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;;&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;len&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;value.length();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;i&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;;&amp;nbsp;i&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;len;&amp;nbsp;i&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;)&amp;nbsp;{&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;seed&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;result&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;value.charAt(i);&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255); &quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;(cap&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0); &quot;&gt;&amp;nbsp;result;&lt;br&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;&lt;br&gt;}&lt;/span&gt;&lt;/div&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; </description><link>http://swinging-breeze.blogspot.com/2010/02/bloom-filter.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item></channel></rss>