﻿<?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-java技术研究</title><link>http://www.blogjava.net/sliverfancy/</link><description /><language>zh-cn</language><lastBuildDate>Sun, 12 Apr 2026 01:16:26 GMT</lastBuildDate><pubDate>Sun, 12 Apr 2026 01:16:26 GMT</pubDate><ttl>60</ttl><item><title>tomcat增加error打印</title><link>http://www.blogjava.net/sliverfancy/archive/2018/08/14/433329.html</link><dc:creator>小秦</dc:creator><author>小秦</author><pubDate>Tue, 14 Aug 2018 04:35:00 GMT</pubDate><guid>http://www.blogjava.net/sliverfancy/archive/2018/08/14/433329.html</guid><wfw:comment>http://www.blogjava.net/sliverfancy/comments/433329.html</wfw:comment><comments>http://www.blogjava.net/sliverfancy/archive/2018/08/14/433329.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sliverfancy/comments/commentRss/433329.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sliverfancy/services/trackbacks/433329.html</trackback:ping><description><![CDATA[<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">今天启动Tomcat启动不了，报以下错：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">org.apache.catalina.core.StandardContext startInternal&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">SEVERE: Error listenerStart&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">org.apache.catalina.core.StandardContext startInternal&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">SEVERE: Context [/******] startup failed due to previous errors&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">网上找了N多文章，都没有切中要害。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">后来在国外网站上搜到一个方法&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">http://grails.1312388.n4.nabble.com/Deployment-problems-td4628710.html。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">我试了一下，是可以的。方案如下。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">Tomcat报的错太含糊了，什么错都没报出来，只提示了Error listenerStart。为了调试，我们要获得更详细的日志。可以在WEB-INF/classes目录下新建一个文件叫logging.properties，内容如下&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><div id="" style="font-family: Monaco, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Consolas, &quot;Courier New&quot;, 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;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #108ac6; text-decoration: underline;"><img src="http://xpenxpen.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border-width: 1px; border-style: solid; border-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;">handlers&nbsp;=&nbsp;org.apache.juli.FileHandler,&nbsp;java.util.logging.ConsoleHandler&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><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;Handler&nbsp;specific&nbsp;properties.&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;Describes&nbsp;specific&nbsp;configuration&nbsp;info&nbsp;<span style="color: #7f0055;">for</span>&nbsp;Handlers.&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><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;">org.apache.juli.FileHandler.level&nbsp;=&nbsp;FINE&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;">org.apache.juli.FileHandler.directory&nbsp;=&nbsp;${catalina.base}/logs&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;">org.apache.juli.FileHandler.prefix&nbsp;=&nbsp;error-debug.&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;">java.util.logging.ConsoleHandler.level&nbsp;=&nbsp;FINE&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;">java.util.logging.ConsoleHandler.formatter&nbsp;=&nbsp;java.util.logging.SimpleFormatter&nbsp;&nbsp;</li></ol></div><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">这样，我们再启动tomcat时，就会在logs目录下生成一个更详细的日志error-debug.2012-05-31.log。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">我们进去看看什么错吧。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">我碰到的错误是FileNotFoundException.大家碰到的错应该各式各样都有，所以就要具体问题具体分析了。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">tomcat的logging文档具体可参考http://tomcat.apache.org/tomcat-7.0-doc/logging.html&nbsp;</span><img src ="http://www.blogjava.net/sliverfancy/aggbug/433329.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sliverfancy/" target="_blank">小秦</a> 2018-08-14 12:35 <a href="http://www.blogjava.net/sliverfancy/archive/2018/08/14/433329.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>服务器一般达到多少qps比较好</title><link>http://www.blogjava.net/sliverfancy/archive/2016/06/08/430828.html</link><dc:creator>小秦</dc:creator><author>小秦</author><pubDate>Wed, 08 Jun 2016 02:23:00 GMT</pubDate><guid>http://www.blogjava.net/sliverfancy/archive/2016/06/08/430828.html</guid><wfw:comment>http://www.blogjava.net/sliverfancy/comments/430828.html</wfw:comment><comments>http://www.blogjava.net/sliverfancy/archive/2016/06/08/430828.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sliverfancy/comments/commentRss/430828.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sliverfancy/services/trackbacks/430828.html</trackback:ping><description><![CDATA[<pre id="best-content-2170306838" accuse="aContent"  mb-10"="" style="margin-top: 0px; margin-bottom: 10px; padding: 0px; font-family: arial, 'courier new', courier, 宋体, monospace, 'Microsoft YaHei'; white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 24px; background-color: #f3ffec;">每秒查询率QPS是对一个特定的查询服务器在规定时间内所处理流量多少的衡量标准，在因特网上，作为域名系统服务器的机器的性能经常用每秒查询率来衡量。<br /><br />原理：每天80%的访问集中在20%的时间里，这20%时间叫做峰值时间 <br />公式：( 总PV数 * 80% ) / ( 每天秒数 * 20% ) = 峰值时间每秒请求数(QPS) <br />机器：峰值时间每秒QPS / 单台机器的QPS = 需要的机器 <br /><br />问：每天300w PV 的在单台机器上，这台机器需要多少QPS？ <br />答：( 3000000 * 0.8 ) / (86400 * 0.2 ) = 139 (QPS) <br /><br />问：如果一台机器的QPS是58，需要几台机器来支持？ <br />答：139 / 58 = 3 <br /></pre><img src ="http://www.blogjava.net/sliverfancy/aggbug/430828.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sliverfancy/" target="_blank">小秦</a> 2016-06-08 10:23 <a href="http://www.blogjava.net/sliverfancy/archive/2016/06/08/430828.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>敏捷开发之Scrum扫盲篇（转）</title><link>http://www.blogjava.net/sliverfancy/archive/2016/04/28/430273.html</link><dc:creator>小秦</dc:creator><author>小秦</author><pubDate>Thu, 28 Apr 2016 03:14:00 GMT</pubDate><guid>http://www.blogjava.net/sliverfancy/archive/2016/04/28/430273.html</guid><wfw:comment>http://www.blogjava.net/sliverfancy/comments/430273.html</wfw:comment><comments>http://www.blogjava.net/sliverfancy/archive/2016/04/28/430273.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/sliverfancy/comments/commentRss/430273.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sliverfancy/services/trackbacks/430273.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">现在敏捷开发是越来越火了，人人都在谈敏捷，人人都在学习Scrum和XP...</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">为了不落后他人，于是我也开始学习Scrum，今天主要是对我最近阅读的相关资料，根据自己的理解，用自己的话来讲述Scrum中的各个环节，主要目的有两个，一个是进行知识的总结，另外一个是觉得网上很多学习资料的讲述方式让初学者不太容易理解；所以我决定写一篇扫盲性的博文，同时试着也与园内的朋友一起分享交流一下，希望对初学者有帮助。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px; font-size: 12px;">&nbsp;什么是敏捷开发？</strong></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">敏捷开发(Agile Development)是一种以人为核心、迭代、循序渐进的开发方法。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">怎么理解呢？首先，我们要理解它不是一门技术，它是一种开发方法，也就是一种软件开发的流程，它会指导我们用规定的环节去一步一步完成项目的开发；而这种开发方式的主要驱动核心是人；它采用的是迭代式开发；</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px; font-size: 12px;">为什么说是以人为核心？</strong></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">我们大部分人都学过瀑布开发模型，它是以文档为驱动的，为什么呢？因为在瀑布的整个开发过程中，要写大量的文档，把需求文档写出来后，开发人员都是根据文档进行开发的，一切以文档为依据；而敏捷开发它只写有必要的文档，或尽量少写文档，敏捷开发注重的是人与人之间，面对面的交流，所以它强调以人为核心。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px; font-size: 12px;">什么是迭代？</strong></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">迭代是指把一个复杂且开发周期很长的开发任务，分解为很多小周期可完成的任务，这样的一个周期就是一次迭代的过程；同时每一次迭代都可以生产或开发出一个可以交付的软件产品。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px; font-size: 12px;">关于Scrum和XP</strong></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">前面说了敏捷它是一种指导思想或开发方式，但是它没有明确告诉我们到底采用什么样的流程进行开发，而Scrum和XP就是敏捷开发的具体方式了，你可以采用Scrum方式也可以采用XP方式；Scrum和XP的区别是，Scrum偏重于过程，XP则偏重于实践，但是实际中，两者是结合一起应用的，这里我主要讲Scrum。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px; font-size: 12px;">什么是Scrum？</strong></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">Scrum的英文意思是橄榄球运动的一个专业术语，表示&#8220;争球&#8221;的动作；把一个开发流程的名字取名为Scrum，我想你一定能想象出你的开发团队在开发一个项目时，大家像打橄榄球一样迅速、富有战斗激情、人人你争我抢地完成它，你一定会感到非常兴奋的。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">而Scrum就是这样的一个开发流程，运用该流程，你就能看到你团队高效的工作。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">【Scrum开发流程中的三大角色】</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px; font-size: 12px;">产品负责人（Product Owner）</strong></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">主要负责确定产品的功能和达到要求的标准，指定软件的发布日期和交付的内容，同时有权力接受或拒绝开发团队的工作成果。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px; font-size: 12px;">流程管理员（Scrum Master）</strong></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">主要负责整个Scrum流程在项目中的顺利实施和进行，以及清除挡在客户和开发工作之间的沟通障碍，使得客户可以直接驱动开发。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px; font-size: 12px;">开发团队（Scrum Team）</strong></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">主要负责软件产品在Scrum规定流程下进行开发工作，人数控制在5~10人左右，每个成员可能负责不同的技术方面，但要求每成员必须要有很强的自我管理能力，同时具有一定的表达能力；成员可以采用任何工作方式，只要能达到Sprint的目标。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px; font-size: 12px; color: red;">Scrum流程图</strong></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><img border="0" alt="" src="http://images.cnblogs.com/cnblogs_com/taven/201010/ScrumModel.jpg" width="646" height="379" style="margin: 0px 0px 20px; padding: 0px; border: 0px; max-width: 800px; width: 646px; height: 379px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">//------------------------</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">下面，我们开始讲具体实施流程，但是在讲之前，我还要对一个英文单词进行讲解。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px; font-size: 12px;">什么是Sprint？</strong></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">Sprint是短距离赛跑的意思，这里面指的是一次迭代，而一次迭代的周期是1个月时间（即4个星期），也就是我们要把一次迭代的开发内容以最快的速度完成它，这个过程我们称它为Sprint。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px; font-size: 12px;">如何进行Scrum开发？</strong></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">1、我们首先需要确定一个Product Backlog（按优先顺序排列的一个产品需求列表），这个是由Product Owner 负责的；</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">2、Scrum Team根据Product Backlog列表，做工作量的预估和安排；</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">3、有了Product Backlog列表，我们需要通过 Sprint Planning Meeting（Sprint计划会议） 来从中挑选出一个Story作为本次迭代完成的目标，这个目标的时间周期是1~4个星期，然后把这个Story进行细化，形成一个Sprint Backlog；</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">4、Sprint Backlog是由Scrum Team去完成的，每个成员根据Sprint Backlog再细化成更小的任务（细到每个任务的工作量在2天内能完成）；</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">5、在Scrum Team完成计划会议上选出的Sprint Backlog过程中，需要进行 Daily Scrum Meeting（每日站立会议），每次会议控制在15分钟左右，每个人都必须发言，并且要向所有成员当面汇报你昨天完成了什么，并且向所有成员承诺你今天要完成什么，同时遇到不能解决的问题也可以提出，每个人回答完成后，要走到黑板前更新自己的&nbsp;Sprint burn down（Sprint燃尽图）；</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">6、做到每日集成，也就是每天都要有一个可以成功编译、并且可以演示的版本；很多人可能还没有用过自动化的每日集成，其实TFS就有这个功能，它可以支持每次有成员进行签入操作的时候，在服务器上自动获取最新版本，然后在服务器中编译，如果通过则马上再执行单元测试代码，如果也全部通过，则将该版本发布，这时一次正式的签入操作才保存到TFS中，中间有任何失败，都会用邮件通知项目管理人员；</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">7、当一个Story完成，也就是Sprint Backlog被完成，也就表示一次Sprint完成，这时，我们要进行&nbsp;Srpint Review Meeting（演示会议），也称为评审会议，产品负责人和客户都要参加（最好本公司老板也参加），每一个Scrum Team的成员都要向他们演示自己完成的软件产品（这个会议非常重要，一定不能取消）；</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">8、最后就是&nbsp;Sprint Retrospective&nbsp;Meeting（回顾会议），也称为总结会议，以轮流发言方式进行，每个人都要发言，总结并讨论改进的地方，放入下一轮Sprint的产品需求中；</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">下面是运用Scrum开发流程中的一些场景图：<br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /><img border="0" alt="" src="http://images.cnblogs.com/cnblogs_com/taven/201010/2010-10-17_202447.png" width="637" height="452" style="margin: 0px 0px 20px; padding: 0px; border: 0px; max-width: 800px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">上图是一个 Product Backlog 的示例。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><img border="0" alt="" src="http://images.cnblogs.com/cnblogs_com/taven/201010/2010-10-17_202749.png" width="600" height="450" style="margin: 0px 0px 20px; padding: 0px; border: 0px; max-width: 800px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">上图就是每日的站立会议了，参会人员可以随意姿势站立，任务看板要保证让每个人看到，当每个人发言完后，要走到任务版前更新自己的燃尽图。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /><img border="0" alt="" src="http://images.cnblogs.com/cnblogs_com/taven/201010/2010-10-17_202812.png" width="620" height="433" style="margin: 0px 0px 20px; padding: 0px; border: 0px; max-width: 800px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">任务看版包含 未完成、正在做、已完成 的工作状态，假设你今天把一个未完成的工作已经完成，那么你要把小卡片从未完成区域贴到已完成区域。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><br style="margin: 0px; padding: 0px;" />&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><img border="0" alt="" src="http://images.cnblogs.com/cnblogs_com/taven/201010/2010-10-17_202832.png" style="margin: 0px 0px 20px; padding: 0px; border: 0px; max-width: 800px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">每个人的工作进度和完成情况都是公开的，如果有一个人的工作任务在某一个位置放了好几天，大家都能发现他的工作进度出现了什么问题（成员人数最好是5~7个，这样每人可以使用一种专用颜色的标签纸，一眼就可以从任务版看出谁的工作进度快，谁的工作进度慢）</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><img border="0" alt="" src="http://images.cnblogs.com/cnblogs_com/taven/201010/2010-10-17_202709.png" width="644" height="428" style="margin: 0px 0px 20px; padding: 0px; border: 0px; max-width: 800px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">&nbsp;上图可不是扑克牌，它是计划纸牌，它的作用是防止项目在开发过程中，被某些人所领导。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;">怎么用的呢？比如A程序员开发一个功能，需要5个小时，B程序员认为只需要半小时，那他们各自取相应的牌，藏在手中，最后摊牌，如果时间差距很大，那么A和B就可以讨论A为什么要5个小时...<br />转自：<span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px;">http://www.cnblogs.com/taven/archive/2010/10/17/1853386.html</span></p><img src ="http://www.blogjava.net/sliverfancy/aggbug/430273.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sliverfancy/" target="_blank">小秦</a> 2016-04-28 11:14 <a href="http://www.blogjava.net/sliverfancy/archive/2016/04/28/430273.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>悲观锁与乐观锁（转）</title><link>http://www.blogjava.net/sliverfancy/archive/2016/01/05/428930.html</link><dc:creator>小秦</dc:creator><author>小秦</author><pubDate>Tue, 05 Jan 2016 01:32:00 GMT</pubDate><guid>http://www.blogjava.net/sliverfancy/archive/2016/01/05/428930.html</guid><wfw:comment>http://www.blogjava.net/sliverfancy/comments/428930.html</wfw:comment><comments>http://www.blogjava.net/sliverfancy/archive/2016/01/05/428930.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sliverfancy/comments/commentRss/428930.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sliverfancy/services/trackbacks/428930.html</trackback:ping><description><![CDATA[<pre id="recommend-content-1803089978" accuse="aContent"  mb-10"="" style="margin-top: 0px; margin-bottom: 10px; padding: 0px; font-family: arial, 'courier new', courier, 宋体, monospace, 'Microsoft YaHei'; white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 24px; background-color: #f3ffec;">先申明概念：<br /><br />1、<a href="https://www.baidu.com/s?wd=%E6%82%B2%E8%A7%82%E9%94%81&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">悲观锁</a>，正如其名，它指的是对数据被外界（包括本系统当前的其他事务，以及来自外部系统的<a href="https://www.baidu.com/s?wd=%E4%BA%8B%E5%8A%A1%E5%A4%84%E7%90%86&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">事务处理</a>）修改持保守态度，因此，在整个<a href="https://www.baidu.com/s?wd=%E6%95%B0%E6%8D%AE%E5%A4%84%E7%90%86&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">数据处理</a>过程中，将数据处于锁定状态。<a href="https://www.baidu.com/s?wd=%E6%82%B2%E8%A7%82%E9%94%81&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">悲观锁</a>的实现，往往依靠数据库提供的锁机制（也只有数据库层提供的锁机制才能真正保证数据访问的排他性，否则，即使在本系统中实现了加锁机制，也无法保证外部系统不会修改数据）。<br />2、<a href="https://www.baidu.com/s?wd=%E4%B9%90%E8%A7%82%E9%94%81&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">乐观锁</a>（ Optimistic Locking ） <br />相对<a href="https://www.baidu.com/s?wd=%E6%82%B2%E8%A7%82%E9%94%81&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">悲观锁</a>而言，<a href="https://www.baidu.com/s?wd=%E4%B9%90%E8%A7%82%E9%94%81&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">乐观锁</a>机制采取了更加宽松的加锁机制。悲观锁大多数情况下依靠数据库的锁机制实现，以保证操作最大程度的<a href="https://www.baidu.com/s?wd=%E7%8B%AC%E5%8D%A0%E6%80%A7&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">独占性</a>。但随之而来的就是数据库性能的大量开销，特别是对长事务而言，这样的开销往往无法承受。而<a href="https://www.baidu.com/s?wd=%E4%B9%90%E8%A7%82%E9%94%81&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">乐观锁</a>机制在一定程度上解决了这个问题。乐观锁，大多是基于数据版本（ Version ）记录机制实现。何谓数据版本？即为数据增加一个版本标识，在基于数据库表的版本解决方案中，一般是通过为数据库表增加一个 &#8220;version&#8221; 字段来实现。读取出数据时，将此<a href="https://www.baidu.com/s?wd=%E7%89%88%E6%9C%AC%E5%8F%B7&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">版本号</a>一同读出，之后更新时，对此<a href="https://www.baidu.com/s?wd=%E7%89%88%E6%9C%AC%E5%8F%B7&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">版本号</a>加一。此时，将提交数据的版本数据与数据库表对应记录的当前版本信息进行比对，如果提交的数据<a href="https://www.baidu.com/s?wd=%E7%89%88%E6%9C%AC%E5%8F%B7&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">版本号</a>大于数据库表当前版本号，则予以更新，否则认为是过期数据。<br /><br />所以悲观锁和乐观锁最大的区别是是否一直锁定资源，悲观锁在事物的全流程锁定数据，乐观锁不锁定数据（用<a href="https://www.baidu.com/s?wd=%E8%AF%BB%E5%86%99%E9%94%81&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">读写锁</a>是阻塞事物，而用乐观锁则会导致回滚。这个是一种事物冲突后的不同锁的表象）。乐观锁的最大特点是在最后检查数据是否被修改，如果已被别人修改过，则回滚数据，避免<a href="https://www.baidu.com/s?wd=%E8%84%8F%E6%95%B0%E6%8D%AE&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">脏数据</a>。至于事物是否冲突和加锁没有直接联系，该冲突的还是会冲突，不管你加悲观锁和乐观锁都会冲突。<br /><br />悲观锁和乐观锁都是为了解决丢失更新问题或者是脏读。悲观锁和乐观锁的重点就是是否在读取记录的时候直接上锁。悲观锁的缺点很明显，需要一个持续的数据库连接，这在<a href="https://www.baidu.com/s?wd=web%E5%BA%94%E7%94%A8&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">web应用</a>中已经不适合了。<br /><br />一个比较清楚的场景<br /><br />下面这个假设的实际场景可以比较清楚的帮助我们理解这个问题：<br /><br />a. 假设<a href="https://www.baidu.com/s?wd=%E5%BD%93%E5%BD%93%E7%BD%91&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nyDvuHFWPHbvnjR4PWwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0dnW6vrjf1nW6YrjRdrH6vPs" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">当当网</a>上用户下单买了本书，这时数据库中有条订单号为001的订单，其中有个status字段是&#8217;有效&#8217;,表示该订单是有效的；<br />b. 后台管理人员查询到这条001的订单，并且看到状态是有效的<br />c. 用户发现下单的时候下错了，于是撤销订单，假设运行这样一条SQL: update order_table set status = &#8216;取消&#8217; where order_id = 001;<br />d. 后台管理人员由于在b这步看到状态有效的，这时，虽然用户在c这步已经撤销了订单，可是管理人员并未刷新界面，看到的订单状态还是有效的，于是点击&#8221;发货&#8221;按钮，将该订单发到物流部门，同时运行类似如下SQL，将订单状态改成已发货:update order_table set status = &#8216;已发货&#8217; where order_id = 001<br /><br />观点1：只有冲突非常严重的系统才需要悲观锁；<br />分析：这是更准确的说法；<br />&#8220;所有悲观锁的做法都适合于状态被修改的概率比较高的情况，具体是否合适则需要根据实际情况判断。&#8221;，表达的也是这个意思，不过说法不够准确；的确，之所以用悲观锁就是因为两个用户更新同一条数据的概率高，也就是冲突比较严重的情况下，所以才用悲观锁。<br /><br />观点2：最后提交前作一次select for update检查，然后再提交update也是一种乐观锁的做法<br />分析：这是更准确的说法；<br />的确，这符合传统乐观锁的做法，就是到最后再去检查。但是wiki在解释悲观锁的做法的时候，&#8217;It is not appropriate for use in web application development.&#8217;， 现在已经很少有悲观锁的做法了，所以我自己将这种二次检查的做法也归为悲观锁的变种，因为这在所有乐观锁里面，做法和悲观锁是最接近的，都是先select for update，然后update<br /><br />*****除了上面的观点1和观点2是更准确的说法，下面的所有观点都是错误的***********<br /><br />观点3：这个问题的原因是因为数据库隔离级别是uncommitted read级别；<br />分析：这个观点是错误的；<br />这个过程本身就是在read committed隔离级别下发生的，从a到d每一步，尤其是d这步，并不是因为读到了未提交的数据，仅仅是因为用户界面没有刷新[事实上也不可能做自动刷新，这样相当于数据库一发生改变立刻要刷新了，这需要监听数据库了，显然这是简单问题复杂化了];<br /><br />观点4：悲观锁是指一个用户在更新数据的时候，其他用户不能读取这条记录；也就是update阻塞读才叫悲观锁；<br />分析：这个观点是错的；<br />这在db2背景的开发中尤其常见；因为db2默认就是update会阻塞读；但是这是各个数据库对读写的时候上锁的并发处理实现不一样。但这根本不是悲观锁乐观锁的区别。Oracle可以做到写不阻塞读仅仅是因为做了多版本并发控制(Multiversion concurrency control), <a href="http://en.wikipedia.org/wiki/Multiversion_concurrency_control;" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">http://en.wikipedia.org/wiki/Multiversion_concurrency_control;</a>但是在Oracle里面，一样可以做乐观锁和悲观锁的控制。这本质上是应用层面的选择。<br /><br />观点5：Oracle实际上用的就是乐观锁<br />分析：这个观点是错的；<br />前面说了，Oracle的确可以做到写不阻塞读，但是这不是悲观锁和乐观锁的问题。这是因为实现了多版本并发控制。按照wiki的定义，悲观锁和乐观锁是在应用层面选择的。Oracle的应用只要在第二步做了select for update，就是悲观锁的做法；况且Oracle在任何隔离级别下，除了分布式事务两阶段提交的短暂时间，其他所有情况下都不存在写阻塞读的情况，如果按照这个观点的话那Oracle已经不能做悲观锁了-_-<br /><br />观点6：不需要这么麻烦，只需要在d这步，最后提交更新的时候再做一个普通的select检查一下就可以；[就是double check的做法]<br />分析：这个观点是错的。<br />这个做法其实在<a href="http://www.hetaoblog.com/database-lost-update-pessimistic-lock/" target="_blank" rel="nofollow" style="color: #2d64b3; text-decoration: none;">http://www.hetaoblog.com/database-lost-update-pessimistic-lock/</a>，&#8217;3. 传统悲观锁做法的变通&#8217;这节已经说明了，如果要这么做的话，仍然需要在最后提交更新前double check的时候做一个select for update， 否则select结束到update提交前的时间仍然有可能记录被修改；<br /><br />观点7：应该尽可能使用悲观锁；<br />分析：这个观点是错的；<br />a. 根据悲观锁的概念，用户在读的时候(b这步)就会将记录锁住，直到更新结束的时候才会将锁释放，所以整个锁的过程时间比较长；<br />b. 另外，悲观锁需要有一个持续的数据库连接，这在当今的web应用中已经几乎不存在；wiki上也说了, 悲观锁&#8216;is not appropriate for use in web application development.&#8217;<br /><br />所以，现在大部分应用都应该是乐观锁的；<br />转自：http://zhidao.baidu.com/link?url=MUOUg59oz7-FKwz-zuUviGryfw9J4V63Pd2iWWErorwUpyeL85rznlmYaGDHXjH_ChywA3R1m9XNpx4k7RCCT3rNofjkCxIBYHdsvwr2bVy<br /><br /></pre><img src ="http://www.blogjava.net/sliverfancy/aggbug/428930.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sliverfancy/" target="_blank">小秦</a> 2016-01-05 09:32 <a href="http://www.blogjava.net/sliverfancy/archive/2016/01/05/428930.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Lock和synchronized (转)</title><link>http://www.blogjava.net/sliverfancy/archive/2015/10/27/427932.html</link><dc:creator>小秦</dc:creator><author>小秦</author><pubDate>Tue, 27 Oct 2015 11:08:00 GMT</pubDate><guid>http://www.blogjava.net/sliverfancy/archive/2015/10/27/427932.html</guid><wfw:comment>http://www.blogjava.net/sliverfancy/comments/427932.html</wfw:comment><comments>http://www.blogjava.net/sliverfancy/archive/2015/10/27/427932.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sliverfancy/comments/commentRss/427932.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sliverfancy/services/trackbacks/427932.html</trackback:ping><description><![CDATA[<span style="background-color: #ffffff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">&nbsp; &nbsp; JDK1.5以后，在锁机制方面引入了新的锁-Lock，在网上的说法都比较笼统，结合网上的信息和我的理解这里做个总结。&nbsp;</span><br /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; java现有的锁机制有两种实现方式，J.DK1.4前是通过synchronized实现，JDK1.5后加入java.util.concurrent.locks包下的各种lock（以下简称Lock）&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 先说说代码层的区别。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; synchronized：在代码里，synchronized类似&#8220;面向对象&#8221;，修饰类、方法、对象。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; Lock：不作为修饰，类似&#8220;面向过程&#8221;，在方法中需要锁的时候lock，在结束的时候unlock（一般都在finally块里）。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">例如代码：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><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: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #108ac6; text-decoration: underline;"><img src="http://wupuyuan.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #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;">void</span>&nbsp;method1()&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;">synchronized</span>(<span style="color: #7f0055;">this</span>){<span style="width: auto; border-width: 0px;">//旧锁，无需人工释放</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;System.out.println(<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;</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;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;method2()&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;Lock&nbsp;lock&nbsp;=&nbsp;<span style="color: #7f0055;">new</span>&nbsp;ReentrantLock();&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;lock.lock();<span style="width: auto; border-width: 0px;">//上锁</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;">try</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;System.out.println(<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;">&nbsp;&nbsp;&nbsp;&nbsp;}<span style="color: #7f0055;">finally</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;lock.unlock();<span style="width: auto; border-width: 0px;">//解锁</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;</li></ol></div><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 其次说说性能。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 相关的性能测试网上已经有很多，这里也直接拿来主义，给出结论：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 在并发高是，luck性能优势很明显，在低并发时，synchronized也能取得优势。具体的临界范围比较难定论，下面会讨论。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 现在来分析它们具体的区别。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 锁都是 原子性 的，也可以理解为锁是否在使用的标记，并且比较和设置这个标记的操作是原子性的，不同硬件平台上的jdk实现锁的相关方法都是native的（比如park/unpark），所以不同平台上锁的精确度的等级由这些native的方法决定。所以网上经常可以看见的结论是&#8220;Lock比synchronized有更精确的原子操作&#8221;说的也是native方法（不得不感慨C才是硬件王道）。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">下面继续讨论怎么由代码层到native的过程。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">1、所有对象都自动含有单一的锁，JVM负责跟踪对象被加锁的次数。如果一个对象被解锁，其计数变为0。在任务（线程）第一次给对象加锁的时候，计数变为1。每当这个相同的任务（线程）在此对象上获得锁时，计数会递增。 只有首先获得锁的任务（线程）才能继续获取该对象上的多个锁。每当任务离开时，计数递减，当计数为0的时候，锁被完全释放。synchronized就是基于这个原理，同时synchronized靠某个对象的单一锁技术的次数来判断是否被锁，所以无需（也不能）人工干预锁的获取和释放。如果结合方法调用时的栈和框架（如果对方法的调用过程不熟悉建议看看</span><a href="http://wupuyuan.iteye.com/blog/1157548" target="_blank" style="color: #108ac6; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">http://wupuyuan.iteye.com/blog/1157548</a><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">），不难推测出synchronized原理是基于栈中的某对象来控制一个框架，所以对于synchronized有常用的优化是锁对象不锁方法。实际上synchronized作用于方法时，锁住的是&#8220;this&#8221;，作用于静态方法/属性时，锁住的是存在于永久带的CLASS，相当于这个CLASS的全局锁，锁作用于一般对象时，锁住的是对应代码块。在HotSpot中JVM实现中，锁有个专门的名字：对象监视器。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">当多个线程同时请求某个对象监视器时，对象监视器会设置几种状态用来区分请求的线程&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">Contention List：所有请求锁的线程将被首先放置到该竞争队列，是个虚拟队列，不是实际的Queue的数据结构。</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">Entry List：EntryList与ContentionList逻辑上同属等待队列，ContentionList会被线程并发访问，为了降低对ContentionList队尾的争用，而建立EntryList。，Contention List中那些有资格成为候选人的线程被移到Entry List&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">Wait Set：那些调用wait方法被阻塞的线程被放置到Wait Set&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">OnDeck：任何时刻最多只能有一个线程正在竞争锁，该线程称为OnDeck&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">Owner：获得锁的线程称为Owner&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">!Owner：释放锁的线程&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">2、Lock不同于synchronized面向对象，它基于栈中的框架而不是某个具体对象，所以Lock只需要在栈里设置锁的开始和结束（lock和unlock）的地方就行了（人工必须标明），不用关心框架大小对象的变化等等。这么做的好处是Lock能提供无条件的、可轮询的、定时的、可中断的锁获取操作，相对于synchronized来说，synchronized的锁的获取是释放必须在一个模块里，获取和释放的顺序必须相反，而Lock则可以在不同范围内获取释放，并且顺序无关。java.util.concurrent.locks下的锁类很类似，依赖于java.util.concurrent.AbstractQueuedSynchronizer，它们把所有的Lock接口操作都转嫁到Sync类上，这个类继承了AbstractQueuedSynchronizer，它同时还包含子2个类：NonfairSync 和FairSync 从名字上可以看的出是为了实现公平和非公平性。AbstractQueuedSynchronizer中把所有的的请求线程构成一个队列（一样也是虚拟的），具体的实现可以参考</span><a href="http://blog.csdn.net/chen77716/article/details/6641477" target="_blank" style="color: #108ac6; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">http://blog.csdn.net/chen77716/article/details/6641477#</a><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">，这里我就不复制了。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">3、从jdk的源代码来看，Lock和synchronized的源码基本相同，区别主要在维护的同步队列上。再往下深究就到了native方法了。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">4、还有个改进我也想说下，其实很重要的。线程分阻塞（wait）和非阻塞状态，阻塞状态由操作系统（linux、windows等）完成，当前一个被&#8220;锁&#8221;的线程执行完毕后，有可能在后续的线程队列里还没分配出一个获取锁而被&#8220;唤醒&#8221;的非阻塞线程，即所有线程还都是阻塞状态时，就被系统调度（进入内核的线程是阻塞的），这样会导致内核在用户态和内核态之间来回接换，严重影响锁的性能。在jdk1.6以前主要靠自旋锁来解决，原理是在前一个线程结束后，争用线程可以做一个空循环，继续占有CPU，等待取锁的机会。当然这样做显然也是浪费时间，只是在两种浪费中选取浪费少的&#8230;&#8230;&nbsp; jdk1.6后引入了偏向锁，当线程第一次获得了监视对象，之后让监视对象&#8220;偏向&#8221;这个线程，之后的多次调用则可以避免CAS操作，等于是置了一临时变量来记录位置（类似索引比较）。详细的就涉及到汇编指令了，我也就没太深究，偏向锁性能优于自旋锁，但是还是没有达到HotSpot认为的最佳时间（一个线程上下文切换的时间）。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 综合来看对于所有的高并发情况，采用Lock加锁是最优选择，但是由于历史遗留等问题，synchronized也还是不能完全被淘汰，同时，在低并发情况下，synchronized的性能还是比Lock好的。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;" /><span style="font-family: Arial; line-height: 26px; background-color: #ffffff;">原帖地址：http://wupuyuan.iteye.com/blog/1158655</span><br /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><br /></span><img src ="http://www.blogjava.net/sliverfancy/aggbug/427932.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sliverfancy/" target="_blank">小秦</a> 2015-10-27 19:08 <a href="http://www.blogjava.net/sliverfancy/archive/2015/10/27/427932.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>再叙TIME_WAIT（转）</title><link>http://www.blogjava.net/sliverfancy/archive/2015/10/16/427786.html</link><dc:creator>小秦</dc:creator><author>小秦</author><pubDate>Fri, 16 Oct 2015 06:28:00 GMT</pubDate><guid>http://www.blogjava.net/sliverfancy/archive/2015/10/16/427786.html</guid><wfw:comment>http://www.blogjava.net/sliverfancy/comments/427786.html</wfw:comment><comments>http://www.blogjava.net/sliverfancy/archive/2015/10/16/427786.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sliverfancy/comments/commentRss/427786.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sliverfancy/services/trackbacks/427786.html</trackback:ping><description><![CDATA[<article id="post-316" post="" type-post="" status-publish="" format-standard="" hentry="" category-technical="" tag-linux=""  tag-tcp"="" style="border-bottom-style: none; margin: 0px 0px 1.625em; padding: 4.875em 0px 0px; position: relative; color: #373737; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 24px; background-color: #ffffff;"><header style="margin: 0px auto; width: 584.265625px;"><h1>再叙TIME_WAIT</h1><br /></header><div style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px auto; outline: 0px; padding-top: 1.625em; vertical-align: baseline; width: 584.265625px;"><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">之所以起这样一个题目是因为很久以前我曾经写过一篇介绍TIME_WAIT的<a href="http://huoding.com/2012/01/19/142" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">文章</a>，不过当时基本属于浅尝辄止，并没深入说明问题的来龙去脉，碰巧这段时间反复被别人问到相关的问题，让我觉得有必要全面总结一下，以备不时之需。</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;"></p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">讨论前大家可以拿手头的服务器摸摸底，记住「ss」比「netstat」快：</p><pre style="border: 0px; font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 13px; margin-top: 0px; margin-bottom: 1.625em; outline: 0px; padding: 0.75em 1.625em; vertical-align: baseline; background-color: #f4f4f4; line-height: 1.5; overflow: auto;">shell&gt; ss -ant | awk '     NR&gt;1 {++s[$1]} END {for(k in s) print k,s[k]} '</pre><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">如果你只是想单独查询一下TIME_WAIT的数量，那么还可以更简单一些：</p><pre style="border: 0px; font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 13px; margin-top: 0px; margin-bottom: 1.625em; outline: 0px; padding: 0.75em 1.625em; vertical-align: baseline; background-color: #f4f4f4; line-height: 1.5; overflow: auto;">shell&gt; cat /proc/net/sockstat</pre><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">我猜你一定被巨大无比的TIME_WAIT网络连接总数吓到了！以我个人的经验，对于一台繁忙的Web服务器来说，如果主要以短连接为主，那么其TIME_WAIT网络连接总数很可能会达到几万，甚至十几万。虽然一个TIME_WAIT网络连接耗费的资源无非就是一个端口、一点内存，但是架不住基数大，所以这始终是一个需要面对的问题。</p><h2>为什么会存在TIME_WAIT？</h2><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">TCP在建立连接的时候需要握手，同理，在关闭连接的时候也需要握手。为了更直观的说明关闭连接时握手的过程，我们引用「<a href="http://www.tcpipguide.com/free/index.htm" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">The TCP/IP Guide</a>」中的<a href="http://www.tcpipguide.com/free/t_TCPConnectionTermination.htm" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">例子</a>：</p><div id="attachment_318"  alignnone"="" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0.4em 0px 1.625em; outline: 0px; padding: 9px; vertical-align: baseline; background-color: #eeeeee; max-width: 96%; width: 676px;"><a href="http://huoding.com/wp-content/uploads/2013/12/tcp_close.png" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;"><img wp-image-318"="" src="http://huoding.com/wp-content/uploads/2013/12/tcp_close.png" alt="TCP Close" width="666" height="556" style="border: 1px solid #eeeeee; max-width: 97.5%; height: auto; width: auto; display: block; margin: -2px 0px 0px -2px; padding: 6px;" /></a><p style="border: 0px; font-family: Georgia, serif; font-size: 12px; font-style: inherit; margin: 0px 0px 0.6em; outline: 0px; padding: 10px 0px 5px 40px; vertical-align: baseline; color: #666666; position: relative;">TCP Close</p></div><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">因为TCP连接是双向的，所以在关闭连接的时候，两个方向各自都需要关闭。先发FIN包的一方执行的是主动关闭；后发FIN包的一方执行的是被动关闭。主动关闭的一方会进入TIME_WAIT状态，并且在此状态停留两倍的<a href="http://en.wikipedia.org/wiki/Maximum_Segment_Lifetime" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">MSL</a>时长。</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">穿插一点MSL的知识：MSL指的是报文段的最大生存时间，如果报文段在网络活动了MSL时间，还没有被接收，那么会被丢弃。关于MSL的大小，<a href="http://tools.ietf.org/search/rfc793" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">RFC 793</a>协议中给出的建议是两分钟，不过实际上不同的操作系统可能有不同的设置，以Linux为例，通常是半分钟，两倍的MSL就是一分钟，也就是60秒，并且这个数值是硬编码在<a href="https://github.com/torvalds/linux/blob/master/include/net/tcp.h" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">内核</a>中的，也就是说除非你重新编译内核，否则没法修改它：</p><pre style="border: 0px; font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 13px; margin-top: 0px; margin-bottom: 1.625em; outline: 0px; padding: 0.75em 1.625em; vertical-align: baseline; background-color: #f4f4f4; line-height: 1.5; overflow: auto;">#define TCP_TIMEWAIT_LEN (60*HZ)</pre><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">如果每秒的连接数是一千的话，那么一分钟就可能会产生六万个TIME_WAIT。</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">为什么主动关闭的一方不直接进入CLOSED状态，而是进入TIME_WAIT状态，并且停留两倍的MSL时长呢？这是因为TCP是建立在不可靠网络上的可靠的协议。例子：主动关闭的一方收到被动关闭的一方发出的FIN包后，回应ACK包，同时进入TIME_WAIT状态，但是因为网络原因，主动关闭的一方发送的这个ACK包很可能延迟，从而触发被动连接一方重传FIN包。极端情况下，这一去一回，就是两倍的MSL时长。如果主动关闭的一方跳过TIME_WAIT直接进入CLOSED，或者在TIME_WAIT停留的时长不足两倍的MSL，那么当被动关闭的一方早先发出的延迟包到达后，就可能出现类似下面的问题：</p><ul style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em 2.5em; outline: 0px; padding: 0px; vertical-align: baseline; list-style: square;"><li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">旧的TCP连接已经不存在了，系统此时只能返回RST包</li><li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">新的TCP连接被建立起来了，延迟包可能干扰新的连接</li></ul><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">不管是哪种情况都会让TCP不再可靠，所以TIME_WAIT状态有存在的必要性。</p><h2>如何控制TIME_WAIT的数量？</h2><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">从前面的描述我们可以得出这样的结论：TIME_WAIT这东西没有的话不行，不过太多可能也是个麻烦事。下面让我们看看有哪些方法可以控制TIME_WAIT数量，这里只说一些常规方法，另外一些诸如SO_LINGER之类的方法太过偏门，略过不谈。</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;"><strong style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">ip_conntrack</strong>：顾名思义就是跟踪连接。一旦激活了此模块，就能在系统参数里发现很多用来控制网络连接状态超时的设置，其中自然也包括TIME_WAIT：</p><pre style="border: 0px; font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 13px; margin-top: 0px; margin-bottom: 1.625em; outline: 0px; padding: 0.75em 1.625em; vertical-align: baseline; background-color: #f4f4f4; line-height: 1.5; overflow: auto;">shell&gt; modprobe ip_conntrack shell&gt; sysctl net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait</pre><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">我们可以尝试缩小它的设置，比如十秒，甚至一秒，具体设置成多少合适取决于网络情况而定，当然也可以参考相关的<a href="http://blog.engineyard.com/2012/linux-scalability" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">案例</a>。不过就我的个人意见来说，ip_conntrack引入的问题比解决的还多，比如性能会大幅下降，所以不建议使用。</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;"><strong style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">tcp_tw_recycle</strong>：顾名思义就是回收TIME_WAIT连接。可以说这个内核参数已经变成了大众处理TIME_WAIT的万金油，如果你在网络上搜索TIME_WAIT的解决方案，十有八九会推荐设置它，不过这里隐藏着一个不易察觉的<a href="http://www.litrin.net/2013/03/01/android%E4%B9%8B%E7%BD%91%E7%BB%9C%E4%B8%A2%E5%8C%85%E4%BA%8B%E4%BB%B6/" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">陷阱</a>：</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">当多个客户端通过NAT方式联网并与服务端交互时，服务端看到的是同一个IP，也就是说对服务端而言这些客户端实际上等同于一个，可惜由于这些客户端的时间戳可能存在差异，于是乎从服务端的视角看，便可能出现时间戳错乱的现象，进而直接导致时间戳小的数据包被丢弃。参考：<a href="http://blog.sina.com.cn/s/blog_781b0c850100znjd.html" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">tcp_tw_recycle和tcp_timestamps导致connect失败问题</a>。</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;"><strong style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">tcp_tw_reuse</strong>：顾名思义就是复用TIME_WAIT连接。当创建新连接的时候，如果可能的话会考虑复用相应的TIME_WAIT连接。通常认为「tcp_tw_reuse」比「tcp_tw_recycle」安全一些，这是因为一来TIME_WAIT创建时间必须超过一秒才可能会被复用；二来只有连接的时间戳是递增的时候才会被复用。<a href="https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">官方文档</a>里是这样说的：如果从协议视角看它是安全的，那么就可以使用。这简直就是外交辞令啊！按我的看法，如果网络比较稳定，比如都是内网连接，那么就可以尝试使用。</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">不过需要注意的是在哪里使用，既然我们要复用连接，那么当然应该在连接的发起方使用，而不能在被连接方使用。举例来说：客户端向服务端发起HTTP请求，服务端响应后主动关闭连接，于是TIME_WAIT便留在了服务端，此类情况使用「tcp_tw_reuse」是无效的，因为服务端是被连接方，所以不存在复用连接一说。让我们延伸一点来看，比如说服务端是PHP，它查询另一个MySQL服务端，然后主动断开连接，于是TIME_WAIT就落在了PHP一侧，此类情况下使用「tcp_tw_reuse」是有效的，因为此时PHP相对于MySQL而言是客户端，它是连接的发起方，所以可以复用连接。</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">说明：如果使用tcp_tw_reuse，请激活tcp_timestamps，否则无效。</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;"><strong style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">tcp_max_tw_buckets</strong>：顾名思义就是控制TIME_WAIT总数。<a href="https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">官网文档</a>说这个选项只是为了阻止一些简单的DoS攻击，平常不要人为的降低它。如果缩小了它，那么系统会将多余的TIME_WAIT删除掉，日志里会显示：「TCP: time wait bucket table overflow」。</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">需要提醒大家的是物极必反，曾经看到有人把「tcp_max_tw_buckets」设置成0，也就是说完全抛弃TIME_WAIT，这就有些冒险了，用一句围棋谚语来说：入界宜缓。</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">&#8230;</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">有时候，如果我们换个角度去看问题，往往能得到四两拨千斤的效果。前面提到的例子：客户端向服务端发起HTTP请求，服务端响应后主动关闭连接，于是TIME_WAIT便留在了服务端。这里的关键在于主动关闭连接的是服务端！在关闭TCP连接的时候，先出手的一方注定逃不开TIME_WAIT的宿命，套用一句歌词：把我的悲伤留给自己，你的美丽让你带走。如果客户端可控的话，那么在服务端打开<a href="http://en.wikipedia.org/wiki/HTTP_persistent_connection" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">KeepAlive</a>，尽可能不让服务端主动关闭连接，而让客户端主动关闭连接，如此一来问题便迎刃而解了。</p><p style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">参考文档：</p><ol style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px 0px 1.625em 2.5em; outline: 0px; padding: 0px; vertical-align: baseline; list-style-position: initial; list-style-image: initial;"><li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><a href="http://blog.csdn.net/yunhua_lee/article/details/8146830" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">tcp短连接TIME_WAIT问题解决方法大全（1）&#8212;&#8212;高屋建瓴</a></li><li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><a href="http://blog.csdn.net/yunhua_lee/article/details/8146837" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">tcp短连接TIME_WAIT问题解决方法大全（2）&#8212;&#8212;SO_LINGER</a></li><li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><a href="http://blog.csdn.net/yunhua_lee/article/details/8146845" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">tcp短连接TIME_WAIT问题解决方法大全（3）&#8212;&#8212;tcp_tw_recycle</a></li><li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><a href="http://blog.csdn.net/yunhua_lee/article/details/8146856" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">tcp短连接TIME_WAIT问题解决方法大全（4）&#8212;&#8212;tcp_tw_reuse</a></li><li style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><a href="http://blog.csdn.net/yunhua_lee/article/details/8146862" target="_blank" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">tcp短连接TIME_WAIT问题解决方法大全（5）&#8212;&#8212;tcp_max_tw_buckets</a></li></ol></div><footer style="color: #666666; clear: both; font-size: 12px; line-height: 18px; margin: 0px auto; width: 584.265625px;">此条目由<a href="http://huoding.com/author/laowang" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">老王</a>发表在<a href="http://huoding.com/category/technical" rel="category tag" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">Technical</a>分类目录，并贴了<a href="http://huoding.com/tag/linux" rel="tag" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">Linux</a>、<a href="http://huoding.com/tag/tcp" rel="tag" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">TCP</a>标签。将<a href="http://huoding.com/2013/12/31/316" title="链向再叙TIME_WAIT的固定链接" rel="bookmark" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #1982d1; text-decoration: none;">固定链接</a>加入收藏夹。</footer></article><div id="comments" style="border: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; margin: 0px; outline: 0px; vertical-align: baseline; color: #373737; line-height: 24px; background-color: #ffffff;"><h2>转自<span style="font-size: 15px;">http://huoding.com/2013/12/31/316</span></h2></div><img src ="http://www.blogjava.net/sliverfancy/aggbug/427786.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sliverfancy/" target="_blank">小秦</a> 2015-10-16 14:28 <a href="http://www.blogjava.net/sliverfancy/archive/2015/10/16/427786.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>网络安全与维护</title><link>http://www.blogjava.net/sliverfancy/archive/2015/10/16/427783.html</link><dc:creator>小秦</dc:creator><author>小秦</author><pubDate>Fri, 16 Oct 2015 05:45:00 GMT</pubDate><guid>http://www.blogjava.net/sliverfancy/archive/2015/10/16/427783.html</guid><wfw:comment>http://www.blogjava.net/sliverfancy/comments/427783.html</wfw:comment><comments>http://www.blogjava.net/sliverfancy/archive/2015/10/16/427783.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sliverfancy/comments/commentRss/427783.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sliverfancy/services/trackbacks/427783.html</trackback:ping><description><![CDATA[<div>1、常规网络访问限制：<br />	a、线上运营设备的SSH端口不允许绑定在公网IP地址上，开发只能登录开发机然后通过内网登录这些服务器；<br />	b、开发机、测试机的SSH端口可以绑定在公网IP地址上，SSH端口(22)可以考虑改为非知名端口；<br />	c、线上运营设备、开发机、测试机的防火墙配置，公网只做80(HTTP)、8080(HTTP)、443(HTTPS)、SSH端口(仅限开发机、测试机)对外授权访问；<br />	d、线上运营设备、开发机、测试机除第c点以外所有服务端口禁止绑定在公网IP地址上，尤其是3306端口(MySQL)；<br />2、DB保护，<br />	a、DB服务器不允许配置公网IP（或用防火墙全部禁止公网访问）；<br />	b、DB的root账户不用于业务访问，回收集中管理，开放普通账户做业务逻辑访问，对不同安全要求的库表用不同的账户密码访问；<br />	c、程序不要把DB访问的账户密码写到配置文件中，写入代码或启动时远程到配置中心拉取（此方法比较重，可暂不考虑）。<br />	d、另：DB备份文件可以考虑做加密处理；<br />3、系统安全：<br />	a、设备的root密码回收集中管理，给开发提供普通用户帐号；<br />	b、密码需要定期修改，有强度要求；<br />4、业务访问控制：<br />	a、业务服务逻辑和运营平台，尽量不要提供对用户表和订单表的批量访问接口，如果运营平台确实有这样的需求，需要对特定账户做授权；<br />安全的代价是不方便、效率会下降，需要寻找平衡点。&nbsp;</div><img src ="http://www.blogjava.net/sliverfancy/aggbug/427783.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sliverfancy/" target="_blank">小秦</a> 2015-10-16 13:45 <a href="http://www.blogjava.net/sliverfancy/archive/2015/10/16/427783.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux 系统挂载数据盘（阿里云）转</title><link>http://www.blogjava.net/sliverfancy/archive/2015/04/30/424791.html</link><dc:creator>小秦</dc:creator><author>小秦</author><pubDate>Thu, 30 Apr 2015 08:08:00 GMT</pubDate><guid>http://www.blogjava.net/sliverfancy/archive/2015/04/30/424791.html</guid><wfw:comment>http://www.blogjava.net/sliverfancy/comments/424791.html</wfw:comment><comments>http://www.blogjava.net/sliverfancy/archive/2015/04/30/424791.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sliverfancy/comments/commentRss/424791.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sliverfancy/services/trackbacks/424791.html</trackback:ping><description><![CDATA[<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">转自<a href="http://www.witwebs.com/aliyun-mount-init/">http://www.witwebs.com/aliyun-mount-init/</a><br />阿里云的服务器，国内访问速度，稳定性一直都是不错的。至少我在使用的过程中，还未碰到什么问题。我将自己在使用主机过程的安装和环境配置做一个详细的介绍。仅供新手朋友参考！当我们在购买到阿里云服务器之后，会获得相应的IP地址和管理密码。</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">主要介绍Linux的数据盘的格式化和挂载。</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">大致步骤是： 登陆Linux &gt; 查看硬盘状况 &gt; 分区数据盘&nbsp;&gt; 格式化数据盘&nbsp;&gt;&nbsp;&nbsp;挂载新分区</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">将会用到的命令如下：</p>
<blockquote style="border-top: rgb(214,233,198) 1px solid; border-right: rgb(214,233,198) 1px solid; white-space: normal; word-spacing: 0px; border-bottom: rgb(214,233,198) 1px solid; text-transform: none; color: rgb(85,85,85); padding-bottom: 5px; text-align: left; padding-top: 10px; font: 12px/20px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 15px; margin: 15px auto; border-left: rgb(214,233,198) 3px solid; letter-spacing: normal; padding-right: 15px; background-color: rgb(244,255,239); text-indent: 0px; -webkit-text-stroke-width: 0px">
<p style="font-size: 12px; font-weight: 300; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px 0px 5px; line-height: 20px; padding-right: 0px">df -h &nbsp; 查看已挂载硬盘信息</p>
<p style="font-size: 12px; font-weight: 300; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px 0px 5px; line-height: 20px; padding-right: 0px"><span style="text-indent: 24px">fdisk -l &nbsp; &nbsp;&nbsp;</span><span style="text-indent: 24px">查看磁盘信息，未挂载的也会列出来</span></p>
<p style="font-size: 12px; font-weight: 300; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px 0px 5px; line-height: 20px; padding-right: 0px">fdisk /dev/xvdb &nbsp; &nbsp; 对数据盘进行分区，回车之后，继续<span class="Apple-converted-space">&nbsp;</span><span style="text-indent: 24px">根据提示，依次输入&#8221;n&#8221; ,&#8221;</span><span style="text-indent: 24px">p&#8221;,&#8220;1&#8221;,</span><span style="text-indent: 24px">两次回车，</span><span style="text-indent: 24px">&#8220;wq&#8221;,&nbsp;</span><span style="text-indent: 24px">分区就开始了，很快就会完成</span></p>
<p style="font-size: 12px; font-weight: 300; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px 0px 5px; line-height: 20px; padding-right: 0px">mkfs .ext3 /dev/xvdb1 &nbsp;命令对新分区进行格式化</p>
<p style="font-size: 12px; font-weight: 300; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px 0px 5px; line-height: 20px; padding-right: 0px">echo &#8216;/dev/xvdb1 &nbsp;/www ext3 &nbsp; &nbsp;defaults &nbsp; &nbsp;0 &nbsp;0&#8242; &gt;&gt; /etc/fstab &nbsp;&nbsp;添加分区信息</p>
<p style="font-size: 12px; font-weight: 300; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px 0px 5px; line-height: 20px; padding-right: 0px">mount -a &nbsp; &nbsp; 命令挂载新分区</p></blockquote>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">&nbsp;</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">1：通过Linux &nbsp; SSH 登陆软件登陆你的linux。登陆之后输入命令：df -lh 的界面如图：</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px"><a title="" style="text-decoration: underline; color: rgb(66,139,202)" href="http://www.witwebs.com/wp-content/uploads/2014/03/%E6%8D%95%E8%8E%B7.jpg" data-original-title=""><img class="alignnone size-full wp-image-307" style="max-width: 100%; border-top: 0px; height: auto; border-right: 0px; vertical-align: middle; border-bottom: 0px; border-left: 0px" alt="捕获" src="http://www.witwebs.com/wp-content/uploads/2014/03/%E6%8D%95%E8%8E%B7.jpg" width="450" height="76" /></a></p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">2：输入命令： fdisk -l 查看磁盘状况，可以看到有数据盘： /dev/xvdb &nbsp;而用df没有查看到这个磁盘。所以需要另外挂载。</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px"><img class="alignnone size-full wp-image-305" style="max-width: 100%; border-top: rgb(221,221,221) 0px; height: auto; border-right: rgb(221,221,221) 0px; vertical-align: middle; border-bottom: rgb(221,221,221) 0px; border-left: rgb(221,221,221) 0px; background-color: rgb(251,251,251)" alt="2" src="http://www.witwebs.com/wp-content/uploads/2014/03/2.jpg" width="536" height="325" suffix_src="http://www.witwebs.com/wp-content/uploads/2014/03/2.jpg" suffix_360="3cdd8dfeea20962034f63b0a0411e9b4" /></p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">3： &nbsp; 用 fdisk &nbsp;/dev/xvdb 对数据盘进行分区。根据提示，输入 n， p， 1， 回车，回车， wq。</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">完成之后，再用&nbsp;fdisk -l，就可以看到显示的信息和之前有不同了。</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px"><a title="" style="text-decoration: underline; color: rgb(66,139,202)" href="http://www.witwebs.com/wp-content/uploads/2014/03/3.jpg" data-original-title=""><img class="alignnone size-full wp-image-304" style="max-width: 100%; border-top: rgb(221,221,221) 0px; height: auto; border-right: rgb(221,221,221) 0px; vertical-align: middle; border-bottom: rgb(221,221,221) 0px; border-left: rgb(221,221,221) 0px; background-color: rgb(251,251,251)" alt="3" src="http://www.witwebs.com/wp-content/uploads/2014/03/3.jpg" width="706" height="813" suffix_src="http://www.witwebs.com/wp-content/uploads/2014/03/3.jpg" suffix_360="ea3780948f18bfdc30b0e5d9690d2700" /></a></p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">&nbsp;</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">4：格式化磁盘。 &nbsp;mkfs .ext3 /dev/xvdb1 ,格式化磁盘。完成之后，就可以来挂载分区了。</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px"><a title="" style="text-decoration: underline; color: rgb(66,139,202)" href="http://www.witwebs.com/wp-content/uploads/2014/03/4.jpg" data-original-title=""><img class="alignnone size-full wp-image-303" style="max-width: 100%; border-top: 0px; height: auto; border-right: 0px; vertical-align: middle; border-bottom: 0px; border-left: 0px" alt="4" src="http://www.witwebs.com/wp-content/uploads/2014/03/4.jpg" width="693" height="726" suffix_src="http://www.witwebs.com/wp-content/uploads/2014/03/4.jpg" suffix_360="4759ec09ec8375473d2af894856e8eb9" /></a></p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">&nbsp;</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">5， 挂载分区，首先建立一个目录用来挂载分区。比如： mkdir &nbsp;/www</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">然后把分区信息加入到fstab中：一次执行：</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">echo &#8216;/dev/xvdb1 &nbsp;/www ext3 &nbsp; &nbsp;defaults &nbsp; &nbsp;0 &nbsp;0&#8242; &gt;&gt; /etc/fstab &nbsp;&nbsp;添加分区信息</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">mount -a &nbsp; &nbsp; 命令挂载新分区</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">最后用 df -h 命令查看，将会发现数据盘。</p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px"><a title="" style="text-decoration: underline; color: rgb(217,83,79); outline-width: 0px; outline-style: none; outline-color: invert" href="http://www.witwebs.com/wp-content/uploads/2014/03/5.jpg" data-original-title=""><img class="alignnone size-full wp-image-302" style="max-width: 100%; border-top: 0px; height: auto; border-right: 0px; vertical-align: middle; border-bottom: 0px; border-left: 0px" alt="5" src="http://www.witwebs.com/wp-content/uploads/2014/03/5.jpg" width="1021" height="506" suffix_src="http://www.witwebs.com/wp-content/uploads/2014/03/5.jpg" suffix_360="88c44177faa11a7001bd03d342c73a40" /></a></p>
<p style="white-space: normal; word-spacing: 0px; text-transform: none; color: rgb(85,85,85); text-align: left; font: 14px/25px 'Microsoft Yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif; margin: 0px 0px 15px; letter-spacing: normal; text-indent: 0px; -webkit-text-stroke-width: 0px">OK，希望能帮到各位。</p><img src ="http://www.blogjava.net/sliverfancy/aggbug/424791.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sliverfancy/" target="_blank">小秦</a> 2015-04-30 16:08 <a href="http://www.blogjava.net/sliverfancy/archive/2015/04/30/424791.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>redis安装（原创）</title><link>http://www.blogjava.net/sliverfancy/archive/2015/04/28/424721.html</link><dc:creator>小秦</dc:creator><author>小秦</author><pubDate>Tue, 28 Apr 2015 03:13:00 GMT</pubDate><guid>http://www.blogjava.net/sliverfancy/archive/2015/04/28/424721.html</guid><wfw:comment>http://www.blogjava.net/sliverfancy/comments/424721.html</wfw:comment><comments>http://www.blogjava.net/sliverfancy/archive/2015/04/28/424721.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sliverfancy/comments/commentRss/424721.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sliverfancy/services/trackbacks/424721.html</trackback:ping><description><![CDATA[<div>1、需要先安装gcc和tcl<br /><div>yum install gcc<br /><div>yum install tcl</div></div><br />2、下载并安装redis<br /><div>cd /opt<br />wget http://download.redis.io/releases/redis-3.0.0.tar.gz</div><br /><div>tar -zxvf /opt/redis-3.0.0.tar.gz<br /><br />cd&nbsp;/opt/redis-3.0.0<br />make<br />make test</div>make PREFIX=/opt/redis-3.0.0 install<br /><br />注：PREFIX一定要大写，装好后，会生成/opt/redis-3.0.0/bin目录，里面有启动命令之类的文件。<br /><br />3、启动与关闭<br /><div>redis启动</div><div>/opt/redis-3.0.0/bin/redis-server /opt/redis-3.0.0/redis.conf</div><div><div>redis关闭</div><div>/opt/redis-3.0.0/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown<br />客户端启动<br /><div>/opt/redis-3.0.0/bin/redis-cli<br />set name test<br />get name</div>4、参数修改</div></div>/opt/redis-3.0.0/redis.conf文件修改<br /><br />#后台运行，可以ctrl+c不至于退出<br /><div>daemonize yes</div><br />关于错误提示<br /><div>（1）编辑/etc/sysctl.conf ，最下面加一行vm.overcommit_memory=1，然后sysctl -p 使配置文件生效</div><div></div><div>（2）sysctl vm.overcommit_memory=1</div><br />注：如果使用了云服务器，要记得打开6379端口，否则无法远程访问<br /></div><img src ="http://www.blogjava.net/sliverfancy/aggbug/424721.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sliverfancy/" target="_blank">小秦</a> 2015-04-28 11:13 <a href="http://www.blogjava.net/sliverfancy/archive/2015/04/28/424721.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux上整合apache和svn（多库）原创转载请注明出处</title><link>http://www.blogjava.net/sliverfancy/archive/2015/03/30/423965.html</link><dc:creator>小秦</dc:creator><author>小秦</author><pubDate>Mon, 30 Mar 2015 09:28:00 GMT</pubDate><guid>http://www.blogjava.net/sliverfancy/archive/2015/03/30/423965.html</guid><wfw:comment>http://www.blogjava.net/sliverfancy/comments/423965.html</wfw:comment><comments>http://www.blogjava.net/sliverfancy/archive/2015/03/30/423965.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sliverfancy/comments/commentRss/423965.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sliverfancy/services/trackbacks/423965.html</trackback:ping><description><![CDATA[<div><div>1、svnadmin create /opt/svn/yiss/app/ios1、apache里的httpd.conf配置如下：</div><div>每个库单独</div><div>&lt;Location /yiss/app/ios&gt;#这个是ios项目url上的访问上下文，对应http://IP/yiss/app/ios/</div><div>DAV svn</div><div>SVNPath /opt/svn/yiss/app/ios#这个是svn库的绝对路径</div><div>AuthType Basic#校验方式</div><div>AuthName "please input username/password"#提示信息</div><div>AuthUserFile &nbsp;/opt/svn/passwd#密码文件绝对路径</div><div>AuthzSVNAccessFile /opt/svn/authz#权限文件绝对路径</div><div>Require valid-user</div><div>&lt;/Location&gt;</div><div>&lt;Location /yiss/app/android&gt;#安卓项目访问上下文</div><div>DAV svn</div><div>SVNPath /opt/svn/yiss/app/android</div><div>AuthType Basic</div><div>AuthName "please input username/password"</div><div>AuthUserFile &nbsp;/opt/svn/passwd</div><div>AuthzSVNAccessFile /opt/svn/authz</div><div>Require valid-user</div><div>&lt;/Location&gt;</div><div>&lt;Location /yiss/web/buildscript&gt;</div><div>DAV svn</div><div>SVNPath /opt/svn/yiss/web/buildscript</div><div>AuthType Basic</div><div>AuthName "please input username/password"</div><div>AuthUserFile &nbsp;/opt/svn/passwd</div><div>AuthzSVNAccessFile /opt/svn/authz</div><div>Require valid-user</div><div>&lt;/Location&gt;</div><div></div><div>2、首先要创建/opt/svn/yiss/app目录和/opt/svn/yiss/web</div><div>然后用命令创建svn库</div><div>svnadmin create /opt/svn/yiss/app/ios</div><div>svnadmin create /opt/svn/yiss/app/android</div><div>svnadmin create /opt/svn/yiss/web/buildscript</div><div></div><div>3、创建apache用户和密码，会提示重复输入2次确认。想改密码就多次输入，以最后一次输入的为准。</div><div>htpasswd /opt/svn/passwd wxq</div><div>htpasswd /opt/svn/passwd caowei</div><div>......</div><div></div><div>4、配置权限组/opt/svn/authz</div><div>[groups]</div><div>admin=wxq</div><div>web=caowei,luocan,houlei,gengzhuo,huangwei,wuhaiying,leo</div><div>app=ssh,golden,shawn,leo</div><div></div><div>#admin组用户可以访问所有目录</div><div>[/]</div><div>@admin=rw</div><div>#ios,android,srv,doc,buildscript这些都是库名，这里创建了3个库</div><div>[ios:/]</div><div>@app=rw</div><div>[android:/]</div><div>@app=rw</div><div>[buildscript:/]</div><div>@admin=rw</div><div></div><div>5、给目录及子目录授权，否则会报403forbidden无权限</div><div>chmod 777 /opt/svn -R</div><div></div><div>6、重启svn，启动的时候要以根启动，如果以某个svn库启动，则其他库无法启动。</div><div>killall svnserve</div><div>svnserve -d -r /opt/svn/yiss</div><div></div><div>7、重启apache</div><div>/opt/apache/bin/apachectl restart</div><div>8、浏览测试</div><div>http://115.231.94.x/yiss/app/ios/</div><div>http://115.231.94.x/yiss/app/android/</div><div>http://115.231.94.x/yiss/web/buildscript/</div></div><img src ="http://www.blogjava.net/sliverfancy/aggbug/423965.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sliverfancy/" target="_blank">小秦</a> 2015-03-30 17:28 <a href="http://www.blogjava.net/sliverfancy/archive/2015/03/30/423965.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>