﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-mixer-a</title><link>http://www.blogjava.net/mixer-a/</link><description /><language>zh-cn</language><lastBuildDate>Sun, 03 May 2026 04:33:47 GMT</lastBuildDate><pubDate>Sun, 03 May 2026 04:33:47 GMT</pubDate><ttl>60</ttl><item><title>兼职开发悟出的点点滴滴</title><link>http://www.blogjava.net/mixer-a/archive/2012/08/05/384786.html</link><dc:creator>mixer-a</dc:creator><author>mixer-a</author><pubDate>Sat, 04 Aug 2012 17:27:00 GMT</pubDate><guid>http://www.blogjava.net/mixer-a/archive/2012/08/05/384786.html</guid><wfw:comment>http://www.blogjava.net/mixer-a/comments/384786.html</wfw:comment><comments>http://www.blogjava.net/mixer-a/archive/2012/08/05/384786.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/mixer-a/comments/commentRss/384786.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mixer-a/services/trackbacks/384786.html</trackback:ping><description><![CDATA[<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">作为开发人员，兼职赚外快是很平常的事！兼职又可以为我们带来什么呢？</strong></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</strong></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">个人总结有四点：</strong></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">一、Money是万恶之源，生活所逼，我要赚钱啊！！</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">二、觉得自己技术还不够好，需要通过不断的开发来巩固知识。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">三、接项目做，其实是个精简版项目开发的流程，从业务需求、系统分析与设计、编码、测试，需要的是一个team的相互沟通、合作。在team中实现自我价值，创造价值，获得个人精神升华（这个赞啊！^_^！）。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">四、业务多了，认识的人也会多起来，圈子自然而然就会越滚越大，各行各业的人都有打交道，这个行业，人脉也是相当重要的。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">OK</strong><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">！讲了那么多，理所当然，兼职开发是不是必要的？我们又应该如何去做正确的做出选择？作为一个未出社会的菜鸟，从自己的兼职经历出发，谈谈自己的想法！</strong></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">2011年暑假得到一个机会去了某间公司当PHP开发的实习生，当时应聘的是ASP.NET开发，因公司要求，去搞PHP了，IT行业的第一份工作，过得还算愉快！！当时BOSS对我还是挺好的，教了我很多东西，不仅仅是在技术方面，在为人处事方面也有收获。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">实习结束后，下定决心搞好自己的专业方向.NET开发，因为觉得自己什么都会点，但是却没能把一种技术学得熟练点。一个偶然的机会，BOSS介绍了一份兼职给我，大致跟那位客户沟通过后，主要是为已经上线的网站修改页面和增减功能，应该算是技术支持，技术支持？好吧！基本上要全能型，前端知识，div，css，js要会点，php的joomla开发也要会。这就和我自己的计划冲突了，左思右想，抵挡不住金钱的诱惑，走上了这条忐忑不安的路。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">由2011年12月份开始，正式合作，支付方式是每月基本任务，固定工资。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">刚开始，主要是做页面的修改，前端基础还算可以，吃着老本，感觉也挺轻松的，客户也很好沟通，就是每天耗的时间比以前多了，逐渐地把精力都放到工作上了。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">寒假过后，回校了，发现工作量越来越大，量大是指小问题越来越多，自己没接触过的功能点也越来越多，由于我的客户是负责统筹运营这方面，对code不是很熟悉，于是我只能自己找资料，去QQ群，论坛求助，无形间自己花费的时间就越来越多，往往一个很简单的小问题，却要绕了一个很大的圈才能解决，工作效率低了，自然任务就越积越多，客户也越来越不满意。关键一点，影响自己学习！此时，已经有打算不做的念头，可是付出汗水后，出粮的那一刻，我又淡定了，咳咳！Money作怪啊！我就这样深深地陷入这个死循环中。。。。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">后来因为想开始准备自己的毕设，加上课程设计要开发电子商务网站，最后，决定不干了，2012年4月份底，The Ending！&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">一轮流水账后，究竟问题出在哪里呢？</strong></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">1.支付方式以每月基本任务，固定工资的方式作为兼职开发的合作形式不妥。客户的立场是以最少的资金来榨取更多的利润，当你快速完成了每个任务后，接着新的任务继续来，没有喘息的时间。所以，遵循多劳多得的原则，以每个模块，任务形式处理更佳，但就需要开发人员能够估算好任务时间，把握进度。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">2.历时5个月，周期太长。任何一份工作开始时总是热情高涨，但是随着时间的推移，渐渐的变得越来越懒散，不负责任，只求完成，不求质量。但更可悲的是，企鹅开始隐身，防止客户打扰。额，这种服务态度是不行的，切忌效仿。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">3.时间不够，无法兼顾学习。上课时间4~5个小时，睡眠时间包括午休10个小时，吃饭时间2个小时，体育运动时间1个小时，额！剩下的时间挤吧！</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">4.沟通能力是非常重要。因为不能和客户面对面沟通，难免有些需求会说不清，此时，请不要敷衍，一定要先把完整的需求弄出来，他想要的功能，想要的效果，在自己的能力范围尽量满足他。当自己遇到某些棘手的问题时，不要怕，尽量说出来，虽然他不是很懂code，但是他给的建议，意见可能帮助到你。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">5.单干很累，拥有team是很幸福的事情。往往一个人开发的时候，遇到问题停滞不前，身边有伙伴提点下，事半功倍。等我以后出去工作了，希望能遇到好team。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">6.做重复的工作，浪费时间，也无法从中学到更多的知识。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">最后，来个大杂烩！</strong></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">作为一名学生，兼职开发可以巩固技术，增加开发经验，加强沟通能力。但是要分析利弊，大学四年可以说是学习的黄金时间，在这四年里面，打好基础是非常重要的。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">如果你有好的团队，方可大战拳脚，自己扛不住还有伙伴的帮忙。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">如果业务太多了，接项目就需要有针对性，对那些周期比较短的，项目难度能在自己可控范围内，又能提高自己技术的优先选择。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">如果因为学习时间与做项目冲突了，这时候就要考虑做项目是否对自己提高技术有帮助了？？</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">程序员们，不要总埋怨公司给的工资太少，而耗费自己大量时间去做私活，眼光放长远点，不要总向Money看，与其获取一丁点的钱，倒不如花更多的时间去增值自己，学无止境啊！只有慢慢积累到一定的程度后，技术可以过得了关，加薪没问题，以后大把的钞票接着来！</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">SO，自己也开始找工作了，之前学的知识太散了，现在要专一点。</strong></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #222222; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 24px; text-align: left; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">明天要去广州红帆电脑科技公司笔试面试，公司用VB.NET开发，自己没接触过，加上对这公司不是很了解，有点犹豫了，哎！找工作就是烦！！</strong></p><img src ="http://www.blogjava.net/mixer-a/aggbug/384786.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mixer-a/" target="_blank">mixer-a</a> 2012-08-05 01:27 <a href="http://www.blogjava.net/mixer-a/archive/2012/08/05/384786.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>你想不到的压缩方法：将javascript文件压缩成PNG图像存储</title><link>http://www.blogjava.net/mixer-a/archive/2012/08/05/384785.html</link><dc:creator>mixer-a</dc:creator><author>mixer-a</author><pubDate>Sat, 04 Aug 2012 17:26:00 GMT</pubDate><guid>http://www.blogjava.net/mixer-a/archive/2012/08/05/384785.html</guid><wfw:comment>http://www.blogjava.net/mixer-a/comments/384785.html</wfw:comment><comments>http://www.blogjava.net/mixer-a/archive/2012/08/05/384785.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/mixer-a/comments/commentRss/384785.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mixer-a/services/trackbacks/384785.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; color: #333333; font-family: 微软雅黑, 宋体; font-size: 13px; line-height: 23px; background-color: #ffffff; ">你有没有想过：为了压缩js文件，把js文件转化成PNG图像，然后用 canvas 控件中的 getImageData() 函数将图像再重新读成js文件。我昨天在这里发表的<a title="如果是JS文件限制了你的页面加载速度，不用再担心了" href="http://www.cnblogs.com/ilian/archive/2012/06/20/js-quick-load.html" style="color: #1982d1; text-decoration: none; ">JS文件快速加载</a>的文章中提到了这一方法，有网友对这个做法很感兴趣，于是今天详细解读一下。<br /><br />这样可以做到很高的压缩比，到底有多高，下面会提到。这种方法用到了 canvas 控件，这也意味着只有支持 canvas 控件的浏览器下才有效。<br /><br /></p><p style="margin-top: 10px; color: #333333; font-family: 微软雅黑, 宋体; font-size: 13px; line-height: 23px; background-color: #ffffff; "><img src="http://pic002.cnblogs.com/images/2012/407883/2012062021300755.png" alt="" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 10px; color: #333333; font-family: 微软雅黑, 宋体; font-size: 13px; line-height: 23px; background-color: #ffffff; ">现在你可以看到，上面的图像类似一个噪声图像，但它实际上是一个由124K的 prototype 框架代码转化成的30K的8位PNG图像（压缩比还不错吧）。<br /><br />其实，要将代码转化为图像的格式存储，可以转化成GIF和PNG格式。PNG格式的图像有24位和8位，用24位的RGB图像，每个像素可以存储3字节的数据，如果是用8位的RGB图像，每个像素可以存储1字节的数据。<br /><br />在PHOTOSHOP中做测试发现：一个300x100的纯色杂点8位图像可以压缩到5K，而同样的纯色杂点图像，如果是100x100的24位图像只能压缩到20K。如果是同样图案的8位GIF图像，压缩效果比PNG要差一些。所以，我们选择用8位的PNG图像作为压缩和解压缩的存储格式。<br /><br />现在，我们就需要开始压缩图像了，下面是用PHP写的压缩文件地址。<br /><a href="http://www.cleanthem.com/code/20120620/js-to-png.txt" target="_blank" style="color: #1982d1; text-decoration: none; ">http://www.cleanthem.com/code/20120620/js-to-png.txt</a></p><p style="margin-top: 10px; color: #333333; font-family: 微软雅黑, 宋体; font-size: 13px; line-height: 23px; background-color: #ffffff; ">它读取JS文件并创建一个PNG图像，图像中的每个像素中是一个0-255之间的值，而这个值对应的是JS字符的ascII的值。<br /><br />当然，除了压缩，还要有解压缩，也就是将图像读取为JS文件的过程。这个函数是用JS写的，可以从下面的位置下载这个文件。<br /><a href="http://www.cleanthem.com/code/20120620/pngdata.txt" target="_blank" style="color: #1982d1; text-decoration: none; ">http://www.cleanthem.com/code/20120620/pngdata.txt</a></p><p style="margin-top: 10px; color: #333333; font-family: 微软雅黑, 宋体; font-size: 13px; line-height: 23px; background-color: #ffffff; ">最后给出在线测试地址，在这个网页上，您可以在列表中选择一个PNG图像文件，点击 load file 按钮可以在网页上看到这个图像，在图像的下面是由这个图像所读出来的代码文件。</p><p style="margin-top: 10px; color: #333333; font-family: 微软雅黑, 宋体; font-size: 13px; line-height: 23px; background-color: #ffffff; "><a href="http://www.nihilogic.dk/labs/canvascompress/" target="_blank" style="color: #1982d1; text-decoration: none; ">http://www.nihilogic.dk/labs/canvascompress/</a></p><p style="margin-top: 10px; color: #333333; font-family: 微软雅黑, 宋体; font-size: 13px; line-height: 23px; background-color: #ffffff; ">&nbsp;</p><p style="margin-top: 10px; color: #333333; font-family: 微软雅黑, 宋体; font-size: 13px; line-height: 23px; background-color: #ffffff; "><span style="color: #ff0000; ">注：</span>转载请注明出处，觉得有用就推荐一下吧~</p><img src ="http://www.blogjava.net/mixer-a/aggbug/384785.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mixer-a/" target="_blank">mixer-a</a> 2012-08-05 01:26 <a href="http://www.blogjava.net/mixer-a/archive/2012/08/05/384785.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>也谈 GET 和 POST 的区别</title><link>http://www.blogjava.net/mixer-a/archive/2012/07/29/384256.html</link><dc:creator>mixer-a</dc:creator><author>mixer-a</author><pubDate>Sun, 29 Jul 2012 02:48:00 GMT</pubDate><guid>http://www.blogjava.net/mixer-a/archive/2012/07/29/384256.html</guid><wfw:comment>http://www.blogjava.net/mixer-a/comments/384256.html</wfw:comment><comments>http://www.blogjava.net/mixer-a/archive/2012/07/29/384256.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/mixer-a/comments/commentRss/384256.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mixer-a/services/trackbacks/384256.html</trackback:ping><description><![CDATA[<p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">上个月，博客园精华区有篇文章《&nbsp;<a href="http://www.cnblogs.com/nankezhishi/archive/2012/06/09/getandpost.html" target="_blank" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; border-bottom-width: 1px; border-bottom-style: dashed; ">GET 和 POST 有什么区别？及为什么网上的多数答案都是错的</a>&nbsp;》，文中和回复多是对以下两个问题进行了深究：</p><ul style="list-style-position: initial; list-style-image: initial; margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 45px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; line-height: 27px; text-align: left; background-color: #fefefe; "><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">长度限制</li><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">Url 是否隐藏数据</li></ul><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">在我看来这两者都不是重点，特写此文予以讨论。</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">我们先来看些基本概念：</p><h1>HTTP 基本概念</h1><h2>HTTP Request Methods</h2><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">GET、POST 专业名称是 HTTP Request Methods。但 HTTP Request Methods 不只是 GET 和 POST，完整列表如下：</p><ul style="list-style-position: initial; list-style-image: initial; margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 45px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; line-height: 27px; text-align: left; background-color: #fefefe; "><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">GET</li><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">POST</li><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">PUT</li><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">DELETE</li><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">HEAD</li><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">OPTIONS</li><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">TRACE</li><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">CONNECT</li><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">PATCH</li></ul><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">REST 使用前四个：GET、POST、PUT、DELETE。因些这四个也是经常被一块提及的，将这四个作为关键字进行搜索，你会得到更深入的结果。</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">在一般的 Web 开发中，GET 和 POST 用得最多，网上对这两的讨论也是最多，往往又很肤浅的。</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">更多信息请查看：</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html" target="_blank" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; border-bottom-width: 1px; border-bottom-style: dashed; ">http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html</a></p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol" target="_blank" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; border-bottom-width: 1px; border-bottom-style: dashed; ">http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol</a></p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://zh.wikipedia.org/wiki/REST" target="_blank" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; border-bottom-width: 1px; border-bottom-style: dashed; ">http://zh.wikipedia.org/wiki/REST</a></p><h2>Safe Methods（安全方法）</h2><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">RFC 2616 中定义如下（后面有翻译）：</p><blockquote style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/bq.gif); background-color: #fefefe; color: #666666; margin-left: auto; padding-left: 45px; padding-right: 0px; padding-top: 0px; padding-bottom: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: auto; font-size: 13px; width: 912px; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-position: 0% 0%; background-repeat: no-repeat no-repeat; "><p style="margin-top: 8px; margin-bottom: 8px; text-indent: 0em; ">Implementors should be aware that the software represents the user in their interactions over the Internet, and should be careful to allow the user to be aware of any actions they might take which may have an unexpected significance to themselves or others.</p><p style="margin-top: 8px; margin-bottom: 8px; text-indent: 0em; ">In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.</p><p style="margin-top: 8px; margin-bottom: 8px; text-indent: 0em; ">Naturally, it is not possible to ensure that the server does not generate side-effects as a result of performing a GET request; in fact, some dynamic resources consider that a feature. The important distinction here is that the user did not request the side-effects, so therefore cannot be held accountable for them.</p></blockquote><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">网址：<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.1" target="_blank" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; border-bottom-width: 1px; border-bottom-style: dashed; ">http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.1</a></p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">维基百科中的说明（对 RFC 2616翻译）：</p><blockquote style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/bq.gif); background-color: #fefefe; color: #666666; margin-left: auto; padding-left: 45px; padding-right: 0px; padding-top: 0px; padding-bottom: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: auto; font-size: 13px; width: 912px; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-position: 0% 0%; background-repeat: no-repeat no-repeat; "><p style="margin-top: 8px; margin-bottom: 8px; text-indent: 0em; ">开发者应当意识到他们的<a href="http://zh.wikipedia.org/wiki/%E8%BD%AF%E4%BB%B6" target="_blank" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; border-bottom-width: 1px; border-bottom-style: dashed; ">软件</a>代表了用户在<a href="http://zh.wikipedia.org/wiki/%E5%9B%A0%E7%89%B9%E7%BD%91" target="_blank" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; border-bottom-width: 1px; border-bottom-style: dashed; ">因特网</a>上进行交互，并且应当告知用户，他们正在进行的操作可能对他们自身或者其他人有未曾预料的重要影响。</p><p style="margin-top: 8px; margin-bottom: 8px; text-indent: 0em; ">特别地，对于GET和HEAD方法而言，除了进行获取资源信息外，这些请求不应当再有任何其他意义。也就是说，这些方法应当被认为是&#8220;安全的&#8221;。客户端应当使用其他&#8220;非安全&#8221;方法，例如POST，PUT及DELETE来以特殊的方式（通常是按钮而不是<a href="http://zh.wikipedia.org/wiki/%E8%B6%85%E9%93%BE%E6%8E%A5" target="_blank" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; border-bottom-width: 1px; border-bottom-style: dashed; ">超链接</a>）使得客户能够意识到可能要负的责任（例如一个按钮带来的资金交易）或者被告知正在请求的操作可能是不安全的（例如某个文件将被上传或删除）。</p><p style="margin-top: 8px; margin-bottom: 8px; text-indent: 0em; ">但是，不能想当然地认为服务器在处理某个GET请求时不会产生任何副作用。事实上，很多动态资源会把这作为其特性。这里重要的区别在于用户并没有请求这一副作用，因此不应由用户为这些副作用承担责任。</p></blockquote><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">来源网址：<a href="http://zh.wikipedia.org/wiki/%E8%B6%85%E6%96%87%E6%9C%AC%E4%BC%A0%E8%BE%93%E5%8D%8F%E8%AE%AE#.E5.AE.89.E5.85.A8.E6.96.B9.E6.B3.95" target="_blank" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; border-bottom-width: 1px; border-bottom-style: dashed; ">http://zh.wikipedia.org/wiki/超文本传输协议#.E5.AE.89.E5.85.A8.E6.96.B9.E6.B3.95</a></p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">这部分读起来比较晦涩，不要着急，读完后面的再回头看就好理解了。</p><h1>GET 与 POST 的区别</h1><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">综上所述，可总结如下：</p><ul style="list-style-position: initial; list-style-image: initial; margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 45px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; line-height: 27px; text-align: left; background-color: #fefefe; "><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">GET 仅用来获取查看信息，不能改变服务器信息。</li><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">POST 用来改变服务器信息。</li></ul><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">这里说的改变，包括增加、修改和删除。</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">这是 HTTP 协议中的要求，众多浏览器和浏览器插件都遵守这些约定。如果你的代码不按照这约定来，可能会出现严重的后果。</p><h2>使用 GET 改变服务器信息的严重后果</h2><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">假定你编写的 Web 程序或网站允许 GET 提交的修改，比如允许用户通过以下 Url 直接删除编写为 1024 的订单：</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">&nbsp;&nbsp;&nbsp;~/orders/delete/1024</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">那么在订单的管理（或列表）页面，你可能会定义一个删除连接如下：</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href="/orders/delete/1024"&gt;删除&lt;/a&gt;</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">当然不会这么简单，一般都会在删除之前会提示用户一下，加上确认提示脚本：</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">&nbsp;&nbsp;&nbsp; &lt;a href="/orders/delete/1024" onclick="return confirm('确实要删除吗？')"&gt;删除&lt;/a&gt;</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">（说明：我在这里只是示简单例下，添加确认删除还是建议使用 Unobtrusive JavaScript 方式，可以使用 jQuery。）</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">很多开发人员以为这样就万事大吉了，有了确认提示，也不怕误删。但问题就恰恰出在这里，2005年时，谷歌发布了一款浏览器加速插件：Google Web Accelerator（以下简称 GWA），让这种问题严重的暴露了出来。</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">GWA 通过多种技术来加速，其中一种就是页面预先加载：比如你在查看我这篇文章的时候，GWA 可能把我前一篇或其它文章预先在后台下载，这样你在点击时，就节省了时间，起到了加速的效果。</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">GWA 的预先加载是根据当前页面中的链接来的，根据 HTTP 的协议，点击链接时使用 GET 方法获取信息，因些不会对服务器造成影响。因此 GWA 会放心的加载当前页面链接对应的网页。当然也可能会加速上面提到的订单删除链接，GWA 会无视你的确认删除脚本，直接从后台把 "/orders/delete/1024" 载入，也就意味着 1024 订单已经被删除了。</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">GWA 发布后，很多网站出现了很多莫名其妙的问题，数据无故丢失，商品自动加入了用户的购物车，用户无端地被扣款&#8230;</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">一时问题很严重，后来发现的原因的所在，就是网站开发者没有遵守 HTTP 约定，没有弄明白 GET 和 POST 的区别。</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">可以查看以下文章深入了解这段历史：</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">&nbsp;&nbsp;&nbsp;<a href="http://blogs.adobe.com/cantrell/archives/2005/06/what_have_we_le.html" target="_blank" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; border-bottom-width: 1px; border-bottom-style: dashed; ">http://blogs.adobe.com/cantrell/archives/2005/06/what_have_we_le.html</a></p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">&nbsp;&nbsp;&nbsp;<a href="http://blog.moertel.com/articles/2005/05/06/google-web-accelerator-offers-web-developers-an-important-opportunity" target="_blank" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; border-bottom-width: 1px; border-bottom-style: dashed; ">http://blog.moertel.com/articles/2005/05/06/google-web-accelerator-offers-web-developers-an-important-opportunity</a></p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">而如今，谷歌发布的 Chrome 浏览器，类似的加速功能集成了进去，你可以在&nbsp;<strong>设置 - 显示高级设置</strong>&nbsp;里面看得到：</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; "><a href="http://images.cnblogs.com/cnblogs_com/ldp615/201207/20120727200132438.png" target="_blank" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; border-bottom-width: 1px; border-bottom-style: dashed; "><img title="image" border="0" alt="image" src="http://images.cnblogs.com/cnblogs_com/ldp615/201207/201207272001342588.png" width="684" height="356" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; background-color: #ffffff; border-top-color: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; background-image: none; border-bottom-style: initial; border-left-style: initial; padding-left: 0px; padding-right: 0px; display: inline; border-top-style: initial; border-right-style: initial; padding-top: 0px; " /></a></p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">所以，对服务器有改变的一定要用 POST，GWA 和类似的插件不会提交 POST 表单加速的。</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">删除、查看用户信息收费（比如人才网、婚恋网）、加入购物车等操作还是放在 POST 表单中用 Button 来吧。</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">再回头读维基百科中对 Safe Methods 的说明，相信你会明白很多。</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">注意：但也不是所有对服务器有改变的都要用 POST，比如你点击本文下面的&nbsp;<a href="http://www.cnblogs.com/ldp615/archive/2012/01/15/orderby-extensions.html" target="_blank" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; border-bottom-width: 1px; border-bottom-style: dashed; ">前一篇博文链接</a>&nbsp;，我的文章访问量可能+1，对服务器有所改变，但这种改变是轻微的，影响不大（相对删除、扣款来说），可以放心的使用链接（GET 方式）。</p><h2>基它一些区别：</h2><ul style="list-style-position: initial; list-style-image: initial; margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 45px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; line-height: 27px; text-align: left; background-color: #fefefe; "><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">使用 GET 表单查询，查询结果页面可以收藏；POST 表单不行。</li><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">向服务器发送文件只能使用 POST 表单。</li></ul><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">能想到的大致这些吧。</p><h1>感言</h1><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">之前，我曾学习 ASP.NET 多年，但对 HTTP 几乎一无所知，WebForm 封装了一切：</p><ul style="list-style-position: initial; list-style-image: initial; margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 45px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; line-height: 27px; text-align: left; background-color: #fefefe; "><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">不用去考虑 POST、GET，只需知道 Postback；</li><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">不用多考虑值来回传递，因为有 ViewState；</li><li style="background-image: url(http://common.cnblogs.com/Skins/Minyx2_Lite/images/icon_miniarrow.gif); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 15px; list-style: inherit; background-position: 0px 9px; background-repeat: no-repeat no-repeat; ">不用关心 Html，因为有服务端控件。</li></ul><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">更悲哀的是，我有很长一段时间都认为一个页面上只能有一个 Form。</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">后来做了一段时间 WinForm 后，开始学习 ASP.NET MVC，开始逐步了解 Html、Http 等等，也开始知道了 Post-Redirect-Get 模式等等。</p><p style="line-height: 27px; margin-top: 12px; margin-bottom: 12px; color: #333333; font-family: 微软雅黑, 'Trebuchet MS', Georgia, 'Times New Roman', Times, sans-serif; text-align: left; background-color: #fefefe; ">看到很多人浅浅讨论 GET 和 POST，感到很无奈，WebForm 误人啊。要想进步，还是学学 ASP.NET MVC 吧！</p><img src ="http://www.blogjava.net/mixer-a/aggbug/384256.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mixer-a/" target="_blank">mixer-a</a> 2012-07-29 10:48 <a href="http://www.blogjava.net/mixer-a/archive/2012/07/29/384256.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>抛弃AJAX?! "服务器推"之初体验</title><link>http://www.blogjava.net/mixer-a/archive/2012/07/29/384257.html</link><dc:creator>mixer-a</dc:creator><author>mixer-a</author><pubDate>Sun, 29 Jul 2012 02:48:00 GMT</pubDate><guid>http://www.blogjava.net/mixer-a/archive/2012/07/29/384257.html</guid><wfw:comment>http://www.blogjava.net/mixer-a/comments/384257.html</wfw:comment><comments>http://www.blogjava.net/mixer-a/archive/2012/07/29/384257.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/mixer-a/comments/commentRss/384257.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mixer-a/services/trackbacks/384257.html</trackback:ping><description><![CDATA[<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">以聊天室为例子,说起写聊天室,大家随口都能说出个大概:</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">即每隔一段时间向服务器异步请求更新，用四个字母代替之就是AJAX。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">其实我们转念想想，我们使用AJAX的目的就是使页面能实时地更新，<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #ff0000; ">倘若我们的动态页面能够实时地更新，我们干嘛还费这些周折？</span></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">先看一个小试验：</p><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; background-color: #ffffff; font-size: 12px; line-height: normal; "><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 5px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; "><a href="http://www.cnblogs.com/Gincenzo/archive/2012/07/28/2613643.html" title="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 3px; padding-bottom: 1px; padding-left: 3px; color: green; text-decoration: none; background-color: #f5f5f5 !important; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-image: initial !important; border-width: initial !important; border-color: initial !important; "><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-style: initial; border-color: initial; border-image: initial !important; border-style: initial; border-color: initial; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-width: initial !important; border-color: initial !important; " /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New'; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">1</span> &lt;?<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">php </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">2</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">while</span>(<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">true</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">){ </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">3</span>         <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">echo</span> 'Hello'<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">; </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">4</span>         <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">sleep</span> (1000<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">); </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">5</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">} </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">6</span> ?&gt;</pre><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 5px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; "><a href="http://www.cnblogs.com/Gincenzo/archive/2012/07/28/2613643.html" title="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 3px; padding-bottom: 1px; padding-left: 3px; color: green; text-decoration: none; background-color: #f5f5f5 !important; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-image: initial !important; border-width: initial !important; border-color: initial !important; "><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-style: initial; border-color: initial; border-image: initial !important; border-style: initial; border-color: initial; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-width: initial !important; border-color: initial !important; " /></a></span></div></div><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">如果如我们所愿，则页面将每隔一秒都会显示一个&#8216;hello&#8217;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">看到这，也许知道我们聊天室的消息显示页面该怎么写了，请看伪代码。</p><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; background-color: #ffffff; font-size: 12px; line-height: normal; "><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 5px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; "><a href="http://www.cnblogs.com/Gincenzo/archive/2012/07/28/2613643.html" title="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 3px; padding-bottom: 1px; padding-left: 3px; color: green; text-decoration: none; background-color: #f5f5f5 !important; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-image: initial !important; border-width: initial !important; border-color: initial !important; "><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-style: initial; border-color: initial; border-image: initial !important; border-style: initial; border-color: initial; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-width: initial !important; border-color: initial !important; " /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New'; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 1</span> &lt;?<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">php </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 2</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #800080; ">$currentData</span> =<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; "> getData(); </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 3</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">while</span> (<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">true</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">){ </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 4</span>       <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #800080; ">$differences</span>=<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">getData(); </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 5</span>       <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">if</span> (<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #800080; ">$differences</span>!=<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #800080; ">$currentData</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">){ </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 6</span>                    <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">echo</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #800080; ">$differences</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">; </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 7</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">                   } </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 8</span>       <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">sleep</span> (10000)<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">; </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 9</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">} </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">10</span> ?&gt;</pre><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 5px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; "><a href="http://www.cnblogs.com/Gincenzo/archive/2012/07/28/2613643.html" title="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 3px; padding-bottom: 1px; padding-left: 3px; color: green; text-decoration: none; background-color: #f5f5f5 !important; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-image: initial !important; border-width: initial !important; border-color: initial !important; "><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-style: initial; border-color: initial; border-image: initial !important; border-style: initial; border-color: initial; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-width: initial !important; border-color: initial !important; " /></a></span></div></div><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">可惜光是这样是不能成功滴，因为我们还没考虑到php的缓存和缓冲问题。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">php默认会缓存内容，防止http报文的Header和Data分离。且php会缓冲页面内容直至程序结束再将页面输出。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">知道原因就好办了。好在php提供了关闭缓冲和缓存的方法。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">直接在前面加上</p><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; background-color: #ffffff; font-size: 12px; line-height: normal; "><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New'; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">1</span> output_buffering=0 <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">2</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">ob_end_flush</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">(); </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">3</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">set_time_limit</span>(0);</pre></div><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">则变为:</p><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; background-color: #ffffff; font-size: 12px; line-height: normal; "><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 5px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; "><a href="http://www.cnblogs.com/Gincenzo/archive/2012/07/28/2613643.html" title="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 3px; padding-bottom: 1px; padding-left: 3px; color: green; text-decoration: none; background-color: #f5f5f5 !important; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-image: initial !important; border-width: initial !important; border-color: initial !important; "><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-style: initial; border-color: initial; border-image: initial !important; border-style: initial; border-color: initial; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-width: initial !important; border-color: initial !important; " /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New'; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 1</span> &lt;?<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">php </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 2</span> output_buffering=0<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">; </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 3</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">ob_end_flush</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">(); </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 4</span>  <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 5</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">while</span>(<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">true</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">){ </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 6</span>         <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">echo</span> 'Hello'<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">; </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 7</span>         <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">sleep</span> (1000<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">); </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 8</span>         <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">flush</span>(); <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008000; ">//</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008000; ">强制使PHP输出</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 9</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">} </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">10</span> ?&gt;</pre><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 5px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; "><a href="http://www.cnblogs.com/Gincenzo/archive/2012/07/28/2613643.html" title="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 3px; padding-bottom: 1px; padding-left: 3px; color: green; text-decoration: none; background-color: #f5f5f5 !important; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-image: initial !important; border-width: initial !important; border-color: initial !important; "><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-style: initial; border-color: initial; border-image: initial !important; border-style: initial; border-color: initial; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-width: initial !important; border-color: initial !important; " /></a></span></div></div><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">你会发现第一个显示hello的已经成功了！</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">我们的消息页面就变为</p><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; background-color: #ffffff; font-size: 12px; line-height: normal; "><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 5px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; "><a href="http://www.cnblogs.com/Gincenzo/archive/2012/07/28/2613643.html" title="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 3px; padding-bottom: 1px; padding-left: 3px; color: green; text-decoration: none; background-color: #f5f5f5 !important; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-image: initial !important; border-width: initial !important; border-color: initial !important; "><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-style: initial; border-color: initial; border-image: initial !important; border-style: initial; border-color: initial; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-width: initial !important; border-color: initial !important; " /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New'; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 1</span> &lt;?<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">php </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 2</span> output_buffering=0<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">; </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 3</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">ob_end_flush</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">(); </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 4</span>  <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 5</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #800080; ">$currentData</span> =<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; "> getData(); </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 6</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">while</span> (<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">true</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">){ </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 7</span>       <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #800080; ">$differences</span>=<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">getData(); </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 8</span>       <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">if</span> (<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #800080; ">$differences</span>!=<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #800080; ">$currentData</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">){ </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; "> 9</span>                    <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">echo</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #800080; ">$differences</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">; </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">10</span>                    <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">flush</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">(); </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">11</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">                   } </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">12</span>       <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">sleep</span> (10000<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">); </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">13</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">} </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">14</span> ?&gt;</pre><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 5px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; "><a href="http://www.cnblogs.com/Gincenzo/archive/2012/07/28/2613643.html" title="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 3px; padding-bottom: 1px; padding-left: 3px; color: green; text-decoration: none; background-color: #f5f5f5 !important; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-image: initial !important; border-width: initial !important; border-color: initial !important; "><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-style: initial; border-color: initial; border-image: initial !important; border-style: initial; border-color: initial; border-top-style: none !important; border-right-style: none !important; border-bottom-style: none !important; border-left-style: none !important; border-width: initial !important; border-color: initial !important; border-width: initial !important; border-color: initial !important; " /></a></span></div></div><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">但是在项目最终的实现上，客户端也存在问题：</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">有些浏览器也会在显示之前，缓存接收到的内容。例如&nbsp;Netscape&nbsp;浏览器会在接受到换行或&nbsp;html&nbsp;标记的开头之前缓存内容，并且在接受到&nbsp;&lt;/table&gt;&nbsp;标记之前，不会显示出整个表格。&nbsp;</span><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">IE甚至只有当接受到的256个字节以后才开始显示该页面，所以必须发送一些额外的空格来让这些浏览器显示页面内容。</span></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">至此我们已经用&#8221;服务器推&#8220;解决了的实时更新的问题。其他框架也与普通思路无异，就不再累述了。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">有兴趣的同学可以着手写一个了。呵呵。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 微软雅黑; line-height: normal; background-color: #ffffff; ">欢迎大家一起交流。</p><img src ="http://www.blogjava.net/mixer-a/aggbug/384257.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mixer-a/" target="_blank">mixer-a</a> 2012-07-29 10:48 <a href="http://www.blogjava.net/mixer-a/archive/2012/07/29/384257.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>你应该实现在网站上的30个jQuery插件</title><link>http://www.blogjava.net/mixer-a/archive/2012/07/29/384255.html</link><dc:creator>mixer-a</dc:creator><author>mixer-a</author><pubDate>Sun, 29 Jul 2012 02:46:00 GMT</pubDate><guid>http://www.blogjava.net/mixer-a/archive/2012/07/29/384255.html</guid><wfw:comment>http://www.blogjava.net/mixer-a/comments/384255.html</wfw:comment><comments>http://www.blogjava.net/mixer-a/archive/2012/07/29/384255.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mixer-a/comments/commentRss/384255.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mixer-a/services/trackbacks/384255.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: jQuery插件&nbsp;&nbsp;<a href='http://www.blogjava.net/mixer-a/archive/2012/07/29/384255.html'>阅读全文</a><img src ="http://www.blogjava.net/mixer-a/aggbug/384255.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mixer-a/" target="_blank">mixer-a</a> 2012-07-29 10:46 <a href="http://www.blogjava.net/mixer-a/archive/2012/07/29/384255.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>博客，我要重新认识你</title><link>http://www.blogjava.net/mixer-a/archive/2012/07/18/383454.html</link><dc:creator>mixer-a</dc:creator><author>mixer-a</author><pubDate>Wed, 18 Jul 2012 15:41:00 GMT</pubDate><guid>http://www.blogjava.net/mixer-a/archive/2012/07/18/383454.html</guid><wfw:comment>http://www.blogjava.net/mixer-a/comments/383454.html</wfw:comment><comments>http://www.blogjava.net/mixer-a/archive/2012/07/18/383454.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mixer-a/comments/commentRss/383454.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mixer-a/services/trackbacks/383454.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要:  作为一名菜鸟程序员，几乎整日都在钻研技术，在埋头学习或工作，很少腾出时间去思考，即使偶尔的思考火花也是闪瞬即逝，没有落在手上写出来。庆幸的是有纪律在鞭促着我不停的思考，不断的用博客记录我们的成长和一点点的进步。&nbsp;&nbsp;<a href='http://www.blogjava.net/mixer-a/archive/2012/07/18/383454.html'>阅读全文</a><img src ="http://www.blogjava.net/mixer-a/aggbug/383454.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mixer-a/" target="_blank">mixer-a</a> 2012-07-18 23:41 <a href="http://www.blogjava.net/mixer-a/archive/2012/07/18/383454.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>7月的尾巴，你是XXX</title><link>http://www.blogjava.net/mixer-a/archive/2012/07/18/383453.html</link><dc:creator>mixer-a</dc:creator><author>mixer-a</author><pubDate>Wed, 18 Jul 2012 15:40:00 GMT</pubDate><guid>http://www.blogjava.net/mixer-a/archive/2012/07/18/383453.html</guid><wfw:comment>http://www.blogjava.net/mixer-a/comments/383453.html</wfw:comment><comments>http://www.blogjava.net/mixer-a/archive/2012/07/18/383453.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mixer-a/comments/commentRss/383453.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mixer-a/services/trackbacks/383453.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 七月过完大半了，2012也如此，传说中的世界末日不知是否还敢如期到来。<br>这里对前半年略作小结，顺带也扯些别的。&nbsp;&nbsp;<a href='http://www.blogjava.net/mixer-a/archive/2012/07/18/383453.html'>阅读全文</a><img src ="http://www.blogjava.net/mixer-a/aggbug/383453.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mixer-a/" target="_blank">mixer-a</a> 2012-07-18 23:40 <a href="http://www.blogjava.net/mixer-a/archive/2012/07/18/383453.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>程序员必须知道的几个国外IT网站</title><link>http://www.blogjava.net/mixer-a/archive/2012/07/18/383452.html</link><dc:creator>mixer-a</dc:creator><author>mixer-a</author><pubDate>Wed, 18 Jul 2012 15:39:00 GMT</pubDate><guid>http://www.blogjava.net/mixer-a/archive/2012/07/18/383452.html</guid><wfw:comment>http://www.blogjava.net/mixer-a/comments/383452.html</wfw:comment><comments>http://www.blogjava.net/mixer-a/archive/2012/07/18/383452.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/mixer-a/comments/commentRss/383452.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mixer-a/services/trackbacks/383452.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 这是一个老牌的IT信息网站，从名称上你就能看出，它是关注服务器端编程的，以Java和Java周边信息为主，不过最近它也有向客户端和微软产品扩展的趋势。这个网站最初是以免费发放《Mastering Enterprise JavaBeans》这本电子书出名的  www.itchm.com&nbsp;&nbsp;<a href='http://www.blogjava.net/mixer-a/archive/2012/07/18/383452.html'>阅读全文</a><img src ="http://www.blogjava.net/mixer-a/aggbug/383452.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mixer-a/" target="_blank">mixer-a</a> 2012-07-18 23:39 <a href="http://www.blogjava.net/mixer-a/archive/2012/07/18/383452.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>并行计算框架的Java实现--系列二</title><link>http://www.blogjava.net/mixer-a/archive/2012/07/15/383110.html</link><dc:creator>mixer-a</dc:creator><author>mixer-a</author><pubDate>Sat, 14 Jul 2012 17:21:00 GMT</pubDate><guid>http://www.blogjava.net/mixer-a/archive/2012/07/15/383110.html</guid><wfw:comment>http://www.blogjava.net/mixer-a/comments/383110.html</wfw:comment><comments>http://www.blogjava.net/mixer-a/archive/2012/07/15/383110.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mixer-a/comments/commentRss/383110.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mixer-a/services/trackbacks/383110.html</trackback:ping><description><![CDATA[<div id="blog_content" style="line-height: 1.8em; font-family: Helvetica, Tahoma, Arial, sans-serif; text-align: left; background-color: #ffffff; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">增加对结果的处理：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">1、修改Job，实现Callable接口</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; "><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-weight: bold; ">Java代码&nbsp;<embed wmode="transparent" src="http://shenxueliang.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=public%20abstract%20class%20Job%20implements%20Callable%3CObject%3E%20%7B%0A%0A%09%40Override%0A%09public%20Object%20call()%20throws%20Exception%20%7B%0A%09%09Object%20result%20%3D%20this.execute()%3B%2F%2F%E6%89%A7%E8%A1%8C%E5%AD%90%E7%B1%BB%E5%85%B7%E4%BD%93%E4%BB%BB%E5%8A%A1%0A%09%09synchronized%20(Executer.LOCK)%20%7B%0A%09%09%09%2F%2F%E5%A4%84%E7%90%86%E5%AE%8C%E4%B8%9A%E5%8A%A1%E5%90%8E%EF%BC%8C%E4%BB%BB%E5%8A%A1%E7%BB%93%E6%9D%9F%EF%BC%8C%E9%80%92%E5%87%8F%E7%BA%BF%E7%A8%8B%E6%95%B0%EF%BC%8C%E5%90%8C%E6%97%B6%E5%94%A4%E9%86%92%E4%B8%BB%E7%BA%BF%E7%A8%8B%0A%09%09%09Executer.THREAD_COUNT--%3B%0A%09%09%09Executer.LOCK.notifyAll()%3B%0A%09%09%7D%0A%09%09return%20result%3B%0A%09%7D%0A%09%2F**%0A%09%20*%20%E4%B8%9A%E5%8A%A1%E5%A4%84%E7%90%86%E5%87%BD%E6%95%B0%0A%09%20*%2F%0A%09public%20abstract%20Object%20execute()%3B%0A%0A%7D" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="http://shenxueliang.iteye.com/blog/1592577" title="收藏这段代码" style="color: #108ac6; "><img src="http://shenxueliang.iteye.com/images/icon_star.png" alt="收藏代码" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; 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: #d1d7dc; border-right-color: #d1d7dc; border-bottom-color: #d1d7dc; border-left-color: #d1d7dc; color: #2b91af; "><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">abstract</span>&nbsp;<span style="color: #7f0055; ">class</span>&nbsp;Job&nbsp;<span style="color: #7f0055; ">implements</span>&nbsp;Callable&lt;Object&gt;&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #646464; ">@Override</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;Object&nbsp;call()&nbsp;<span style="color: #7f0055; ">throws</span>&nbsp;Exception&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object&nbsp;result&nbsp;=&nbsp;<span style="color: #7f0055; ">this</span>.execute();//执行子类具体任务&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">synchronized</span>&nbsp;(Executer.LOCK)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//处理完业务后，任务结束，递减线程数，同时唤醒主线程&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Executer.THREAD_COUNT--;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Executer.LOCK.notifyAll();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">return</span>&nbsp;result;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;/**&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;业务处理函数&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">abstract</span>&nbsp;Object&nbsp;execute();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">}&nbsp;&nbsp;</li></ol></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">2、修改Executer，增加对结果的处理</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; "><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-weight: bold; ">Java代码&nbsp;<embed wmode="transparent" src="http://shenxueliang.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=public%20class%20Executer%20%7B%0A%09%2F%2F%E8%AE%A1%E7%AE%97%E5%B7%B2%E7%BB%8F%E6%B4%BE%E5%8F%91%E7%9A%84%E4%BB%BB%E5%8A%A1%E6%95%B0(%E6%9D%A1%E4%BB%B6%E8%B0%93%E8%AF%8D)%0A%09public%20static%20int%20THREAD_COUNT%20%3D%200%3B%0A%09%2F%2F%E5%AD%98%E5%82%A8%E4%BB%BB%E5%8A%A1%E7%9A%84%E6%89%A7%E8%A1%8C%E7%BB%93%E6%9E%9C%0A%09private%20List%3CFuture%3CObject%3E%3E%20futres%20%3D%20new%20ArrayList%3CFuture%3CObject%3E%3E()%3B%20%0A%09%2F%2F%E6%9D%A1%E4%BB%B6%E9%98%9F%E5%88%97%E9%94%81%0A%09public%20static%20final%20Object%20LOCK%20%3D%20new%20Object()%3B%0A%09%2F%2F%E7%BA%BF%E7%A8%8B%E6%B1%A0%0A%09private%20ExecutorService%20pool%20%3D%20null%3B%0A%09public%20Executer()%20%7B%0A%09%09this(1)%3B%0A%09%7D%0A%09public%20Executer(int%20threadPoolSize)%20%7B%0A%09%09pool%20%3D%20Executors.newFixedThreadPool(threadPoolSize)%3B%0A%09%7D%0A%09%2F**%0A%09%20*%20%E4%BB%BB%E5%8A%A1%E6%B4%BE%E5%8F%91%0A%09%20*%20%40param%20job%0A%09%20*%2F%0A%09public%20void%20fork(Job%20job)%7B%0A%09%09%2F%2F%E5%B0%86%E4%BB%BB%E5%8A%A1%E6%B4%BE%E5%8F%91%E7%BB%99%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%8E%BB%E6%89%A7%E8%A1%8C%0A%09%09futres.add(pool.submit(job))%3B%0A%09%09%2F%2F%E5%A2%9E%E5%8A%A0%E7%BA%BF%E7%A8%8B%E6%95%B0%0A%09%09synchronized%20(LOCK)%20%7B%0A%09%09%09THREAD_COUNT%2B%2B%3B%0A%09%09%7D%0A%09%7D%0A%09%2F**%0A%09%20*%20%E7%BB%9F%E8%AE%A1%E4%BB%BB%E5%8A%A1%E7%BB%93%E6%9E%9C%0A%09%20*%2F%0A%09public%20List%3CObject%3E%20join()%7B%0A%09%09synchronized%20(LOCK)%20%7B%0A%09%09%09while(THREAD_COUNT%20%3E%200)%7B%2F%2F%E6%A3%80%E6%9F%A5%E7%BA%BF%E7%A8%8B%E6%95%B0%EF%BC%8C%E5%A6%82%E6%9E%9C%E4%B8%BA0%EF%BC%8C%E5%88%99%E8%A1%A8%E7%A4%BA%E6%89%80%E6%9C%89%E4%BB%BB%E5%8A%A1%E5%A4%84%E7%90%86%E5%AE%8C%E6%88%90%0A%09%09%09%09System.out.println(%22threadCount%3A%20%22%2BTHREAD_COUNT)%3B%0A%09%09%09%09try%20%7B%0A%09%09%09%09%09LOCK.wait()%3B%2F%2F%E5%A6%82%E6%9E%9C%E4%BB%BB%E5%8A%A1%E6%B2%A1%E6%9C%89%E5%85%A8%E9%83%A8%E5%AE%8C%E6%88%90%EF%BC%8C%E5%88%99%E6%8C%82%E8%B5%B7%E3%80%82%E7%AD%89%E5%BE%85%E5%AE%8C%E6%88%90%E7%9A%84%E4%BB%BB%E5%8A%A1%E7%BB%99%E4%BA%88%E9%80%9A%E7%9F%A5%0A%09%09%09%09%7D%20catch%20(InterruptedException%20e)%20%7B%0A%09%09%09%09%09e.printStackTrace()%3B%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09List%3CObject%3E%20list%20%3D%20new%20ArrayList%3CObject%3E()%3B%0A%09%09%2F%2F%E5%8F%96%E5%87%BA%E6%AF%8F%E4%B8%AA%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%A4%84%E7%90%86%E7%BB%93%E6%9E%9C%EF%BC%8C%E6%B1%87%E6%80%BB%E5%90%8E%E8%BF%94%E5%9B%9E%0A%09%09for%20(Future%3CObject%3E%20future%20%3A%20futres)%20%7B%0A%09%09%09try%20%7B%0A%09%09%09%09Object%20result%20%3D%20future.get()%3B%2F%2F%E5%9B%A0%E4%B8%BA%E4%BB%BB%E5%8A%A1%E9%83%BD%E5%B7%B2%E7%BB%8F%E5%AE%8C%E6%88%90%EF%BC%8C%E8%BF%99%E9%87%8C%E7%9B%B4%E6%8E%A5get%0A%09%09%09%09list.add(result)%3B%0A%09%09%09%7D%20catch%20(Exception%20e)%20%7B%0A%09%09%09%09e.printStackTrace()%3B%0A%09%09%09%7D%20%0A%09%09%7D%0A%09%09return%20list%3B%0A%09%7D%0A%7D" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="http://shenxueliang.iteye.com/blog/1592577" title="收藏这段代码" style="color: #108ac6; "><img src="http://shenxueliang.iteye.com/images/icon_star.png" alt="收藏代码" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; 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: #d1d7dc; border-right-color: #d1d7dc; border-bottom-color: #d1d7dc; border-left-color: #d1d7dc; color: #2b91af; "><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">class</span>&nbsp;Executer&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;//计算已经派发的任务数(条件谓词)&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">static</span>&nbsp;<span style="color: #7f0055; ">int</span>&nbsp;THREAD_COUNT&nbsp;=&nbsp;<span style="color: #c00000; ">0</span>;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;//存储任务的执行结果&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">private</span>&nbsp;List&lt;Future&lt;Object&gt;&gt;&nbsp;futres&nbsp;=&nbsp;<span style="color: #7f0055; ">new</span>&nbsp;ArrayList&lt;Future&lt;Object&gt;&gt;();&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;//条件队列锁&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">static</span>&nbsp;<span style="color: #7f0055; ">final</span>&nbsp;Object&nbsp;LOCK&nbsp;=&nbsp;<span style="color: #7f0055; ">new</span>&nbsp;Object();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;//线程池&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">private</span>&nbsp;ExecutorService&nbsp;pool&nbsp;=&nbsp;<span style="color: #7f0055; ">null</span>;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;Executer()&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">this</span>(<span style="color: #c00000; ">1</span>);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;Executer(<span style="color: #7f0055; ">int</span>&nbsp;threadPoolSize)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool&nbsp;=&nbsp;Executors.newFixedThreadPool(threadPoolSize);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;/**&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;任务派发&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;job&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">void</span>&nbsp;fork(Job&nbsp;job){&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//将任务派发给线程池去执行&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;futres.add(pool.submit(job));&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//增加线程数&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">synchronized</span>&nbsp;(LOCK)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;THREAD_COUNT++;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;/**&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;统计任务结果&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;List&lt;Object&gt;&nbsp;join(){&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">synchronized</span>&nbsp;(LOCK)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">while</span>(THREAD_COUNT&nbsp;&gt;&nbsp;<span style="color: #c00000; ">0</span>){//检查线程数，如果为0，则表示所有任务处理完成&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("threadCount:&nbsp;"+THREAD_COUNT);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">try</span>&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LOCK.wait();//如果任务没有全部完成，则挂起。等待完成的任务给予通知&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #7f0055; ">catch</span>&nbsp;(InterruptedException&nbsp;e)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&lt;Object&gt;&nbsp;list&nbsp;=&nbsp;<span style="color: #7f0055; ">new</span>&nbsp;ArrayList&lt;Object&gt;();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//取出每个任务的处理结果，汇总后返回&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">for</span>&nbsp;(Future&lt;Object&gt;&nbsp;future&nbsp;:&nbsp;futres)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">try</span>&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object&nbsp;result&nbsp;=&nbsp;future.get();//因为任务都已经完成，这里直接get&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add(result);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #7f0055; ">catch</span>&nbsp;(Exception&nbsp;e)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">return</span>&nbsp;list;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">}&nbsp;&nbsp;</li></ol></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;3、测试：</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; "><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-weight: bold; ">Java代码&nbsp;<embed wmode="transparent" src="http://shenxueliang.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=public%20static%20void%20main(String%5B%5D%20args)%20%7B%0A%09%09%2F%2F%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BB%BB%E5%8A%A1%E6%B1%A0%0A%09%09Executer%20exe%20%3D%20new%20Executer(5)%3B%0A%09%09%2F%2F%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BB%BB%E5%8A%A1%0A%09%09long%20time%20%3D%20System.currentTimeMillis()%3B%0A%09%09for%20(int%20i%20%3D%200%3B%20i%20%3C%2010%3B%20i%2B%2B)%20%7B%0A%09%09%09MyJob%20job%20%3D%20new%20MyJob()%3B%0A%09%09%09exe.fork(job)%3B%2F%2F%E6%B4%BE%E5%8F%91%E4%BB%BB%E5%8A%A1%0A%09%09%7D%0A%09%09%2F%2F%E6%B1%87%E6%80%BB%E4%BB%BB%E5%8A%A1%E7%BB%93%E6%9E%9C%0A%09%09List%3CObject%3E%20list%20%3D%20exe.join()%3B%0A%09%09System.out.println(%22Result%3A%20%22%2Blist)%3B%0A%09%09System.out.println(%22time%3A%20%22%2B(System.currentTimeMillis()%20-%20time))%3B%0A%09%7D" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="http://shenxueliang.iteye.com/blog/1592577" title="收藏这段代码" style="color: #108ac6; "><img src="http://shenxueliang.iteye.com/images/icon_star.png" alt="收藏代码" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; 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: #d1d7dc; border-right-color: #d1d7dc; border-bottom-color: #d1d7dc; border-left-color: #d1d7dc; color: #2b91af; "><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">static</span>&nbsp;<span style="color: #7f0055; ">void</span>&nbsp;main(String[]&nbsp;args)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//初始化任务池&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Executer&nbsp;exe&nbsp;=&nbsp;<span style="color: #7f0055; ">new</span>&nbsp;Executer(<span style="color: #c00000; ">5</span>);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//初始化任务&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">long</span>&nbsp;time&nbsp;=&nbsp;System.currentTimeMillis();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">for</span>&nbsp;(<span style="color: #7f0055; ">int</span>&nbsp;i&nbsp;=&nbsp;<span style="color: #c00000; ">0</span>;&nbsp;i&nbsp;&lt;&nbsp;<span style="color: #c00000; ">10</span>;&nbsp;i++)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyJob&nbsp;job&nbsp;=&nbsp;<span style="color: #7f0055; ">new</span>&nbsp;MyJob();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exe.fork(job);//派发任务&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//汇总任务结果&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&lt;Object&gt;&nbsp;list&nbsp;=&nbsp;exe.join();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Result:&nbsp;"+list);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("time:&nbsp;"+(System.currentTimeMillis()&nbsp;-&nbsp;time));&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li></ol></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">4、执行结果：</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; "><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-weight: bold; ">Java代码&nbsp;<embed wmode="transparent" src="http://shenxueliang.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=threadCount%3A%2010%0Arunning%20thread%20id%20%3D%209%0Arunning%20thread%20id%20%3D%2011%0Arunning%20thread%20id%20%3D%208%0Arunning%20thread%20id%20%3D%2010%0Arunning%20thread%20id%20%3D%2012%0AthreadCount%3A%205%0Arunning%20thread%20id%20%3D%209%0Arunning%20thread%20id%20%3D%208%0Arunning%20thread%20id%20%3D%2011%0Arunning%20thread%20id%20%3D%2012%0Arunning%20thread%20id%20%3D%2010%0AResult%3A%20%5B8%2C%209%2C%2010%2C%2011%2C%2012%2C%208%2C%2011%2C%2012%2C%209%2C%2010%5D%0Atime%3A%202000" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="http://shenxueliang.iteye.com/blog/1592577" title="收藏这段代码" style="color: #108ac6; "><img src="http://shenxueliang.iteye.com/images/icon_star.png" alt="收藏代码" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; 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: #d1d7dc; border-right-color: #d1d7dc; border-bottom-color: #d1d7dc; border-left-color: #d1d7dc; color: #2b91af; "><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">threadCount:&nbsp;<span style="color: #c00000; ">10</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">9</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">11</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">8</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">10</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">12</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">threadCount:&nbsp;<span style="color: #c00000; ">5</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">9</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">8</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">11</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">12</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">10</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">Result:&nbsp;[<span style="color: #c00000; ">8</span>,&nbsp;<span style="color: #c00000; ">9</span>,&nbsp;<span style="color: #c00000; ">10</span>,&nbsp;<span style="color: #c00000; ">11</span>,&nbsp;<span style="color: #c00000; ">12</span>,&nbsp;<span style="color: #c00000; ">8</span>,&nbsp;<span style="color: #c00000; ">11</span>,&nbsp;<span style="color: #c00000; ">12</span>,&nbsp;<span style="color: #c00000; ">9</span>,&nbsp;<span style="color: #c00000; ">10</span>]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">time:&nbsp;<span style="color: #c00000; ">2000</span>&nbsp;&nbsp;</li></ol></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">5、附件是完整代码</p></div><div style="border-top-width: 1px; border-top-style: solid; border-top-color: #999999; margin-top: 10px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #ffffff; "><ul style="margin-top: 5px; margin-right: 5px; margin-bottom: 5px; margin-left: 5px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; list-style-type: none; list-style-position: initial; list-style-image: initial; 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: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><a href="http://dl.iteye.com/topics/download/577fafbc-aae3-3250-b2d0-7ffc66cf24df" style="color: #108ac6; ">src.rar</a>&nbsp;(2.2 KB)</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">下载次数: 11</li></ul></div><img src ="http://www.blogjava.net/mixer-a/aggbug/383110.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mixer-a/" target="_blank">mixer-a</a> 2012-07-15 01:21 <a href="http://www.blogjava.net/mixer-a/archive/2012/07/15/383110.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>并行计算框架的Java实现--系列三</title><link>http://www.blogjava.net/mixer-a/archive/2012/07/15/383111.html</link><dc:creator>mixer-a</dc:creator><author>mixer-a</author><pubDate>Sat, 14 Jul 2012 17:21:00 GMT</pubDate><guid>http://www.blogjava.net/mixer-a/archive/2012/07/15/383111.html</guid><wfw:comment>http://www.blogjava.net/mixer-a/comments/383111.html</wfw:comment><comments>http://www.blogjava.net/mixer-a/archive/2012/07/15/383111.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mixer-a/comments/commentRss/383111.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mixer-a/services/trackbacks/383111.html</trackback:ping><description><![CDATA[<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">优化锁，之前的锁是采用一个static的Object实现的，这要就会有一个问题，如果我创建了多个Executer，那么所有Job都会持有一把锁，既影响性能，也容易出现死锁的情况。所以，改成每个Executer持有一把锁。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">Executer代码如下：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25px; text-align: left; "><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-weight: bold; ">Java代码&nbsp;<embed wmode="transparent" src="http://shenxueliang.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=public%20class%20Executer%20%7B%0A%09%2F%2F%E8%AE%A1%E7%AE%97%E5%B7%B2%E7%BB%8F%E6%B4%BE%E5%8F%91%E7%9A%84%E4%BB%BB%E5%8A%A1%E6%95%B0(%E6%9D%A1%E4%BB%B6%E8%B0%93%E8%AF%8D)%0A%09public%20static%20int%20THREAD_COUNT%20%3D%200%3B%0A%09%2F%2F%E5%AD%98%E5%82%A8%E4%BB%BB%E5%8A%A1%E7%9A%84%E6%89%A7%E8%A1%8C%E7%BB%93%E6%9E%9C%0A%09private%20List%3CFuture%3CObject%3E%3E%20futres%20%3D%20new%20ArrayList%3CFuture%3CObject%3E%3E()%3B%20%0A%09%2F%2F%E6%9D%A1%E4%BB%B6%E9%98%9F%E5%88%97%E9%94%81%0A%09public%20final%20Object%20lock%20%3D%20new%20Object()%3B%0A%09%2F%2F%E7%BA%BF%E7%A8%8B%E6%B1%A0%0A%09private%20ExecutorService%20pool%20%3D%20null%3B%0A%09public%20Executer()%20%7B%0A%09%09this(1)%3B%0A%09%7D%0A%09public%20Executer(int%20threadPoolSize)%20%7B%0A%09%09pool%20%3D%20Executors.newFixedThreadPool(threadPoolSize)%3B%0A%09%7D%0A%09%2F**%0A%09%20*%20%E4%BB%BB%E5%8A%A1%E6%B4%BE%E5%8F%91%0A%09%20*%20%40param%20job%0A%09%20*%2F%0A%09public%20void%20fork(Job%20job)%7B%0A%09%09%2F%2F%E8%AE%BE%E7%BD%AE%E5%90%8C%E6%AD%A5%E9%94%81%0A%09%09job.setLock(lock)%3B%0A%09%09%2F%2F%E5%B0%86%E4%BB%BB%E5%8A%A1%E6%B4%BE%E5%8F%91%E7%BB%99%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%8E%BB%E6%89%A7%E8%A1%8C%0A%09%09futres.add(pool.submit(job))%3B%0A%09%09%2F%2F%E5%A2%9E%E5%8A%A0%E7%BA%BF%E7%A8%8B%E6%95%B0%0A%09%09synchronized%20(lock)%20%7B%0A%09%09%09THREAD_COUNT%2B%2B%3B%0A%09%09%7D%0A%09%7D%0A%09%2F**%0A%09%20*%20%E7%BB%9F%E8%AE%A1%E4%BB%BB%E5%8A%A1%E7%BB%93%E6%9E%9C%0A%09%20*%2F%0A%09public%20List%3CObject%3E%20join()%7B%0A%09%09synchronized%20(lock)%20%7B%0A%09%09%09while(THREAD_COUNT%20%3E%200)%7B%2F%2F%E6%A3%80%E6%9F%A5%E7%BA%BF%E7%A8%8B%E6%95%B0%EF%BC%8C%E5%A6%82%E6%9E%9C%E4%B8%BA0%EF%BC%8C%E5%88%99%E8%A1%A8%E7%A4%BA%E6%89%80%E6%9C%89%E4%BB%BB%E5%8A%A1%E5%A4%84%E7%90%86%E5%AE%8C%E6%88%90%0A%09%09%09%09System.out.println(%22threadCount%3A%20%22%2BTHREAD_COUNT)%3B%0A%09%09%09%09try%20%7B%0A%09%09%09%09%09lock.wait()%3B%2F%2F%E5%A6%82%E6%9E%9C%E4%BB%BB%E5%8A%A1%E6%B2%A1%E6%9C%89%E5%85%A8%E9%83%A8%E5%AE%8C%E6%88%90%EF%BC%8C%E5%88%99%E6%8C%82%E8%B5%B7%E3%80%82%E7%AD%89%E5%BE%85%E5%AE%8C%E6%88%90%E7%9A%84%E4%BB%BB%E5%8A%A1%E7%BB%99%E4%BA%88%E9%80%9A%E7%9F%A5%0A%09%09%09%09%7D%20catch%20(InterruptedException%20e)%20%7B%0A%09%09%09%09%09e.printStackTrace()%3B%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09List%3CObject%3E%20list%20%3D%20new%20ArrayList%3CObject%3E()%3B%0A%09%09%2F%2F%E5%8F%96%E5%87%BA%E6%AF%8F%E4%B8%AA%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%A4%84%E7%90%86%E7%BB%93%E6%9E%9C%EF%BC%8C%E6%B1%87%E6%80%BB%E5%90%8E%E8%BF%94%E5%9B%9E%0A%09%09for%20(Future%3CObject%3E%20future%20%3A%20futres)%20%7B%0A%09%09%09try%20%7B%0A%09%09%09%09Object%20result%20%3D%20future.get()%3B%2F%2F%E5%9B%A0%E4%B8%BA%E4%BB%BB%E5%8A%A1%E9%83%BD%E5%B7%B2%E7%BB%8F%E5%AE%8C%E6%88%90%EF%BC%8C%E8%BF%99%E9%87%8C%E7%9B%B4%E6%8E%A5get%0A%09%09%09%09list.add(result)%3B%0A%09%09%09%7D%20catch%20(Exception%20e)%20%7B%0A%09%09%09%09e.printStackTrace()%3B%0A%09%09%09%7D%20%0A%09%09%7D%0A%09%09return%20list%3B%0A%09%7D%0A%7D" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="http://shenxueliang.iteye.com/blog/1593057" title="收藏这段代码" style="color: #108ac6; "><img src="http://shenxueliang.iteye.com/images/icon_star.png" alt="收藏代码" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; 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: #d1d7dc; border-right-color: #d1d7dc; border-bottom-color: #d1d7dc; border-left-color: #d1d7dc; color: #2b91af; "><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">class</span>&nbsp;Executer&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;//计算已经派发的任务数(条件谓词)&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">static</span>&nbsp;<span style="color: #7f0055; ">int</span>&nbsp;THREAD_COUNT&nbsp;=&nbsp;<span style="color: #c00000; ">0</span>;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;//存储任务的执行结果&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">private</span>&nbsp;List&lt;Future&lt;Object&gt;&gt;&nbsp;futres&nbsp;=&nbsp;<span style="color: #7f0055; ">new</span>&nbsp;ArrayList&lt;Future&lt;Object&gt;&gt;();&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;//条件队列锁&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">final</span>&nbsp;Object&nbsp;lock&nbsp;=&nbsp;<span style="color: #7f0055; ">new</span>&nbsp;Object();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;//线程池&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">private</span>&nbsp;ExecutorService&nbsp;pool&nbsp;=&nbsp;<span style="color: #7f0055; ">null</span>;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;Executer()&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">this</span>(<span style="color: #c00000; ">1</span>);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;Executer(<span style="color: #7f0055; ">int</span>&nbsp;threadPoolSize)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool&nbsp;=&nbsp;Executors.newFixedThreadPool(threadPoolSize);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;/**&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;任务派发&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;job&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">void</span>&nbsp;fork(Job&nbsp;job){&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//设置同步锁&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;job.setLock(lock);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//将任务派发给线程池去执行&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;futres.add(pool.submit(job));&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//增加线程数&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">synchronized</span>&nbsp;(lock)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;THREAD_COUNT++;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;/**&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;统计任务结果&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;List&lt;Object&gt;&nbsp;join(){&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">synchronized</span>&nbsp;(lock)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">while</span>(THREAD_COUNT&nbsp;&gt;&nbsp;<span style="color: #c00000; ">0</span>){//检查线程数，如果为0，则表示所有任务处理完成&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("threadCount:&nbsp;"+THREAD_COUNT);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">try</span>&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lock.wait();//如果任务没有全部完成，则挂起。等待完成的任务给予通知&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #7f0055; ">catch</span>&nbsp;(InterruptedException&nbsp;e)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&lt;Object&gt;&nbsp;list&nbsp;=&nbsp;<span style="color: #7f0055; ">new</span>&nbsp;ArrayList&lt;Object&gt;();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//取出每个任务的处理结果，汇总后返回&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">for</span>&nbsp;(Future&lt;Object&gt;&nbsp;future&nbsp;:&nbsp;futres)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">try</span>&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object&nbsp;result&nbsp;=&nbsp;future.get();//因为任务都已经完成，这里直接get&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add(result);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #7f0055; ">catch</span>&nbsp;(Exception&nbsp;e)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">return</span>&nbsp;list;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">}&nbsp;&nbsp;</li></ol></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;Job类:</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25px; text-align: left; "><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-weight: bold; ">Java代码&nbsp;<embed wmode="transparent" src="http://shenxueliang.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=public%20abstract%20class%20Job%20implements%20Callable%3CObject%3E%20%7B%0A%0A%09%2F%2F%E9%94%81%0A%09private%20Object%20lock%20%3D%20null%3B%0A%0A%09void%20setLock(Object%20lock)%20%7B%0A%09%09this.lock%20%3D%20lock%3B%0A%09%7D%0A%0A%09%40Override%0A%09public%20Object%20call()%20throws%20Exception%20%7B%0A%09%09Object%20result%20%3D%20this.execute()%3B%2F%2F%E6%89%A7%E8%A1%8C%E5%AD%90%E7%B1%BB%E5%85%B7%E4%BD%93%E4%BB%BB%E5%8A%A1%0A%09%09synchronized%20(lock)%20%7B%0A%09%09%09%2F%2F%E5%A4%84%E7%90%86%E5%AE%8C%E4%B8%9A%E5%8A%A1%E5%90%8E%EF%BC%8C%E4%BB%BB%E5%8A%A1%E7%BB%93%E6%9D%9F%EF%BC%8C%E9%80%92%E5%87%8F%E7%BA%BF%E7%A8%8B%E6%95%B0%EF%BC%8C%E5%90%8C%E6%97%B6%E5%94%A4%E9%86%92%E4%B8%BB%E7%BA%BF%E7%A8%8B%0A%09%09%09Executer.THREAD_COUNT--%3B%0A%09%09%09lock.notifyAll()%3B%0A%09%09%7D%0A%09%09return%20result%3B%0A%09%7D%0A%09%2F**%0A%09%20*%20%E4%B8%9A%E5%8A%A1%E5%A4%84%E7%90%86%E5%87%BD%E6%95%B0%0A%09%20*%2F%0A%09public%20abstract%20Object%20execute()%3B%0A%09%0A%7D" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="http://shenxueliang.iteye.com/blog/1593057" title="收藏这段代码" style="color: #108ac6; "><img src="http://shenxueliang.iteye.com/images/icon_star.png" alt="收藏代码" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; 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: #d1d7dc; border-right-color: #d1d7dc; border-bottom-color: #d1d7dc; border-left-color: #d1d7dc; color: #2b91af; "><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">abstract</span>&nbsp;<span style="color: #7f0055; ">class</span>&nbsp;Job&nbsp;<span style="color: #7f0055; ">implements</span>&nbsp;Callable&lt;Object&gt;&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;//锁&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">private</span>&nbsp;Object&nbsp;lock&nbsp;=&nbsp;<span style="color: #7f0055; ">null</span>;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">void</span>&nbsp;setLock(Object&nbsp;lock)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">this</span>.lock&nbsp;=&nbsp;lock;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #646464; ">@Override</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;Object&nbsp;call()&nbsp;<span style="color: #7f0055; ">throws</span>&nbsp;Exception&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object&nbsp;result&nbsp;=&nbsp;<span style="color: #7f0055; ">this</span>.execute();//执行子类具体任务&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">synchronized</span>&nbsp;(lock)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//处理完业务后，任务结束，递减线程数，同时唤醒主线程&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Executer.THREAD_COUNT--;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lock.notifyAll();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">return</span>&nbsp;result;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;/**&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;业务处理函数&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">abstract</span>&nbsp;Object&nbsp;execute();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">}&nbsp;&nbsp;</li></ol></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;测试结果：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25px; text-align: left; "><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-weight: bold; ">Java代码&nbsp;<embed wmode="transparent" src="http://shenxueliang.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=threadCount%3A%2010%0Arunning%20thread%20id%20%3D%208%0Arunning%20thread%20id%20%3D%2010%0Arunning%20thread%20id%20%3D%209%0Arunning%20thread%20id%20%3D%2012%0Arunning%20thread%20id%20%3D%2011%0AthreadCount%3A%208%0AthreadCount%3A%207%0AthreadCount%3A%206%0AthreadCount%3A%205%0Arunning%20thread%20id%20%3D%2012%0Arunning%20thread%20id%20%3D%208%0Arunning%20thread%20id%20%3D%2011%0AthreadCount%3A%202%0Arunning%20thread%20id%20%3D%2010%0AthreadCount%3A%201%0Arunning%20thread%20id%20%3D%209%0AResultSize%3A%2010%0Atime%3A%202001" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="http://shenxueliang.iteye.com/blog/1593057" title="收藏这段代码" style="color: #108ac6; "><img src="http://shenxueliang.iteye.com/images/icon_star.png" alt="收藏代码" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; 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: #d1d7dc; border-right-color: #d1d7dc; border-bottom-color: #d1d7dc; border-left-color: #d1d7dc; color: #2b91af; "><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">threadCount:&nbsp;<span style="color: #c00000; ">10</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">8</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">10</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">9</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">12</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">11</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">threadCount:&nbsp;<span style="color: #c00000; ">8</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">threadCount:&nbsp;<span style="color: #c00000; ">7</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">threadCount:&nbsp;<span style="color: #c00000; ">6</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">threadCount:&nbsp;<span style="color: #c00000; ">5</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">12</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">8</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">11</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">threadCount:&nbsp;<span style="color: #c00000; ">2</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">10</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">threadCount:&nbsp;<span style="color: #c00000; ">1</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">running&nbsp;thread&nbsp;id&nbsp;=&nbsp;<span style="color: #c00000; ">9</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">ResultSize:&nbsp;<span style="color: #c00000; ">10</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">time:&nbsp;<span style="color: #c00000; ">2001</span>&nbsp;&nbsp;</li></ol></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;OK！</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">这样每个Executer就可以使用自己的lock，而相互不受同步的影响</p><img src ="http://www.blogjava.net/mixer-a/aggbug/383111.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mixer-a/" target="_blank">mixer-a</a> 2012-07-15 01:21 <a href="http://www.blogjava.net/mixer-a/archive/2012/07/15/383111.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>