??xml version="1.0" encoding="utf-8" standalone="yes"?>成人a视频在线,国产真实乱对白精彩久久,超碰免费在线观看http://www.aygfsteel.com/kxbin/category/40783.html创出一片天?/description>zh-cnWed, 21 Mar 2012 22:08:09 GMTWed, 21 Mar 2012 22:08:09 GMT60java synchronized详解(?http://www.aygfsteel.com/kxbin/articles/371112.htmlkxbinkxbinFri, 02 Mar 2012 01:22:00 GMThttp://www.aygfsteel.com/kxbin/articles/371112.htmlhttp://www.aygfsteel.com/kxbin/comments/371112.htmlhttp://www.aygfsteel.com/kxbin/articles/371112.html#Feedback0http://www.aygfsteel.com/kxbin/comments/commentRss/371112.htmlhttp://www.aygfsteel.com/kxbin/services/trackbacks/371112.html阅读全文

kxbin 2012-03-02 09:22 发表评论
]]>
Set与List之间转化http://www.aygfsteel.com/kxbin/articles/366982.htmlkxbinkxbinThu, 22 Dec 2011 01:13:00 GMThttp://www.aygfsteel.com/kxbin/articles/366982.htmlhttp://www.aygfsteel.com/kxbin/comments/366982.htmlhttp://www.aygfsteel.com/kxbin/articles/366982.html#Feedback0http://www.aygfsteel.com/kxbin/comments/commentRss/366982.htmlhttp://www.aygfsteel.com/kxbin/services/trackbacks/366982.htmlList list = new ArrayList(set);
Set set = new HashSet(list);
//但是有一?转换当中可能要丢失数?其是从list转换到set的时?因ؓset不能有重复数?//q有转换到set之后,他们原先在list上的序没?
public class Csdn {
    
public static void main(String[] args) {
        List
<String> list = new ArrayList<String>();
        Collections.addAll(list,
"zhao","long","ri");//填充
        Set
<String> set=new HashSet<String>();
        set.addAll(list);
//lset填充
        list.clear();
//清空listQ不然下ơ把set元素加入此list的时候是在原来的基础上追加元素的
        list.addAll(set);
//把set?/span>
    }
}


kxbin 2011-12-22 09:13 发表评论
]]>
JAVA反射机制Q{Q?/title><link>http://www.aygfsteel.com/kxbin/articles/365690.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Tue, 06 Dec 2011 09:14:00 GMT</pubDate><guid>http://www.aygfsteel.com/kxbin/articles/365690.html</guid><wfw:comment>http://www.aygfsteel.com/kxbin/comments/365690.html</wfw:comment><comments>http://www.aygfsteel.com/kxbin/articles/365690.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/kxbin/comments/commentRss/365690.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/kxbin/services/trackbacks/365690.html</trackback:ping><description><![CDATA[     摘要: 一、什么是反射Q反的概念是由Smith?982q首ơ提出的Q主要是指程序可以访问、检和修改它本w状态或行ؓ的一U能力。这一概念的提出很快引发了计算机科学领域关于应用反性的研究。它首先被程序语a的设计领域所采用,q在Lisp和面向对象方面取得了成W。其中LEAD/LEAD++ 、OpenC++ 、MetaXa和OpenJava{就是基于反机制的语言。最q,反射机制也被应用C视窗pȝ、操?..  <a href='http://www.aygfsteel.com/kxbin/articles/365690.html'>阅读全文</a><img src ="http://www.aygfsteel.com/kxbin/aggbug/365690.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/kxbin/" target="_blank">kxbin</a> 2011-12-06 17:14 <a href="http://www.aygfsteel.com/kxbin/articles/365690.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java synchronized详解http://www.aygfsteel.com/kxbin/articles/365636.htmlkxbinkxbinTue, 06 Dec 2011 00:43:00 GMThttp://www.aygfsteel.com/kxbin/articles/365636.htmlhttp://www.aygfsteel.com/kxbin/comments/365636.htmlhttp://www.aygfsteel.com/kxbin/articles/365636.html#Feedback0http://www.aygfsteel.com/kxbin/comments/commentRss/365636.htmlhttp://www.aygfsteel.com/kxbin/services/trackbacks/365636.html阅读全文

kxbin 2011-12-06 08:43 发表评论
]]>
探烦q发~程Q七Q?-----分布式环境中q发问题Q{Q?/title><link>http://www.aygfsteel.com/kxbin/articles/361160.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Thu, 13 Oct 2011 08:05:00 GMT</pubDate><guid>http://www.aygfsteel.com/kxbin/articles/361160.html</guid><wfw:comment>http://www.aygfsteel.com/kxbin/comments/361160.html</wfw:comment><comments>http://www.aygfsteel.com/kxbin/articles/361160.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/kxbin/comments/commentRss/361160.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/kxbin/services/trackbacks/361160.html</trackback:ping><description><![CDATA[<div><span style="color: #333333; font-family: Arial; font-size: 17px; line-height: 25px; "><p>在分布式环境中,处理q发问题没办法通过操作pȝ和JVM的工h解决Q那么在分布式环境中Q可以采取一下策略和方式来处理:</p><ul><li>避免q发</li><li>旉?/li><li>串行?/li><li>数据?/li><li>行锁</li><li>l一触发途径</li></ul><p><strong>避免q发</strong></p><p>在分布式环境中,如果存在q发问题Q那么很N过技术去解决Q或者解决的代h(hun)很大Q所以我们首先要x是不是可以通过某些{略和业务设计来避免q发。比如通过合理的时间调度,避开׃n资源的存取冲H。另外,在ƈ行Q务设计上可以通过适当的策略,保证d与Q务之间不存在׃n资源Q比如在以前博文中提到的例子Q我们需要用多线E或分布式集来计算一堆客L相关l计|׃客户的统计值是׃n数据Q因此会有ƈ发潜在可能。但从业务上我们可以分析出客户与客户之间 数据是不׃n的,因此可以设计一个规则来保证一个客L计算工作和数据访问只会被一个线E或一台工作机完成Q而不是把一个客L计算工作分配l多个线E去 完成。这U规则很Ҏ(gu)设计Q例如可以采用hash法?/p><p><strong>旉?/strong></p><p>分布式环境中q发是没法保证时序的Q无论是通过q程接口的同步调用或异步消息Q因此很Ҏ(gu)造成某些Ҏ(gu)序性有要求的业务在高ƈ发时产生错误。比如系lA需要把某个值的变更同步到系lBQ由于通知的时序问题会D一个过期的D盖了有效倹{对于这个问题,常用的办法就是采用时间戳的方式,每次pȝA发送变更给pȝB的时候需要带上一个能标示时序的时间戳Q系lB接到通知后会拿时间戳与存在的旉x较,只有当通知的时间戳大于存在的时间戳Q才做更新。这U方式比较简单,但关键在于调用方一般要保证旉戳的时序有效性?/p><p><strong>串行?/strong></p><p>有的时候可以通过串行化可能生ƈ发问题操作,牺牲性能和扩展性,来满_数据一致性的要求。比如分布式消息pȝ没法保证消息的有序性,但可以通过变分布式消息pȝ为单一pȝ可以保证消息的有序性了。另外,当接收方没法处理调用有序性,可以通过一个队列先把调用信息缓存v来,然后再串行地处理q些调用?/p><p><strong>数据?/strong></p><p>分布式环境中的共享资源不能通过Java里同步方法或加锁来保证线E安全,但数据库是分布式各服务器的共享点Q可以通过数据库的高可靠一致性机制来满需求。比如,可以通过唯一性烦引来解决q发q程中重复数据的生或重复Q务的执行Q另外有些更新计操作也量通过sql来完成,因ؓ在程序段计算好后再去更新有可能发生脏复写问题,但通过一条sql来完成计和更新可以通过数据库的锁机制来保证update操作的一致性?/p><p><strong>行锁</strong></p><p>有的事务比较复杂Q无法通过一条sql解决问题Qƈ且有存在q发问题Q这时就需要通过行锁来解冻I一般行锁可以通过以下方式来实玎ͼ</p><ul><li>对于Oracle数据库,可以采用select ... for update方式。这U方式会有潜在的危险Q就是如果没有commit׃造成q行数据被锁住,其他有涉及到q行数据的Q务都会被挂vQ应该}慎?/li><li>在表里添加一个标C锁的字D,每次操作前,先通过updateq个锁字D|完成cM竞争锁的操作Q操作完成后在update锁字D复位,标示已归q锁。这U方式比较安全,不好的地方在于这些update锁字D늚操作是额外的性能消?/li></ul><p><strong>l一触发途径</strong></p><p>当一个数据可能会被多个触发点或多个业务涉及到Q就有ƈ发问题生的隐?zhn)Q因此可以通过前期架构和业务设计,量l一触发途径Q触发途径了一是减ƈ发的可能Q也有利于对于ƈ发问题的分析和判断?/p></span></div><img src ="http://www.aygfsteel.com/kxbin/aggbug/361160.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/kxbin/" target="_blank">kxbin</a> 2011-10-13 16:05 <a href="http://www.aygfsteel.com/kxbin/articles/361160.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>探烦q发~程Q五Q?-----Java多线E开发技巧(转)http://www.aygfsteel.com/kxbin/articles/361158.htmlkxbinkxbinThu, 13 Oct 2011 08:04:00 GMThttp://www.aygfsteel.com/kxbin/articles/361158.htmlhttp://www.aygfsteel.com/kxbin/comments/361158.htmlhttp://www.aygfsteel.com/kxbin/articles/361158.html#Feedback0http://www.aygfsteel.com/kxbin/comments/commentRss/361158.htmlhttp://www.aygfsteel.com/kxbin/services/trackbacks/361158.html阅读全文

kxbin 2011-10-13 16:04 发表评论
]]>
探烦q发~程Q六Q?-----Java多线E性能优化Q{Q?/title><link>http://www.aygfsteel.com/kxbin/articles/361159.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Thu, 13 Oct 2011 08:04:00 GMT</pubDate><guid>http://www.aygfsteel.com/kxbin/articles/361159.html</guid><wfw:comment>http://www.aygfsteel.com/kxbin/comments/361159.html</wfw:comment><comments>http://www.aygfsteel.com/kxbin/articles/361159.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/kxbin/comments/commentRss/361159.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/kxbin/services/trackbacks/361159.html</trackback:ping><description><![CDATA[     摘要: 大家使用多线E无非是Z提高性能Q但如果多线E用不当,不但性能提升不明显,而且会得资源消耗更大。下面列举一下可能会造成多线E性能问题的点Q死锁过多串行化q多锁竞争切换上下文内存同步下面分别解析以上性能隐?zhn)死锁关于死锁Q我们在学习操作pȝ的时候就知道它生的原因和危宻Iq里׃从原理上ȝqCQ可以从下面的代码和囄重温一下死锁生的原因Q?nbsp;public class ...  <a href='http://www.aygfsteel.com/kxbin/articles/361159.html'>阅读全文</a><img src ="http://www.aygfsteel.com/kxbin/aggbug/361159.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/kxbin/" target="_blank">kxbin</a> 2011-10-13 16:04 <a href="http://www.aygfsteel.com/kxbin/articles/361159.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>探烦q发~程Q四Q?-----Javaq发工具Q{Q?/title><link>http://www.aygfsteel.com/kxbin/articles/361157.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Thu, 13 Oct 2011 08:02:00 GMT</pubDate><guid>http://www.aygfsteel.com/kxbin/articles/361157.html</guid><wfw:comment>http://www.aygfsteel.com/kxbin/comments/361157.html</wfw:comment><comments>http://www.aygfsteel.com/kxbin/articles/361157.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/kxbin/comments/commentRss/361157.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/kxbin/services/trackbacks/361157.html</trackback:ping><description><![CDATA[     摘要: ZU程安全的一些原则来~程当然可以避免q发问题Q但不是所有h都能写出高质量的U程安全的代码,q且如果代码里到处都是线E安全的控制也极大地影响了代码可L和可维护性。因此,Javaq_Z解决q个问题Q提供了很多U程安全的类和ƈ发工P通过q些cd工具p更简便地写线E安全的代码。归U一下有以下几种Q同步容器类q发容器cȝ产者和消费者模式阻塞和可中断方法Synchronizerq些cdҎ(gu)的用都...  <a href='http://www.aygfsteel.com/kxbin/articles/361157.html'>阅读全文</a><img src ="http://www.aygfsteel.com/kxbin/aggbug/361157.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/kxbin/" target="_blank">kxbin</a> 2011-10-13 16:02 <a href="http://www.aygfsteel.com/kxbin/articles/361157.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>探烦q发~程Q三Q?-----Java存储模型和共享对象(转)http://www.aygfsteel.com/kxbin/articles/361156.htmlkxbinkxbinThu, 13 Oct 2011 07:47:00 GMThttp://www.aygfsteel.com/kxbin/articles/361156.htmlhttp://www.aygfsteel.com/kxbin/comments/361156.htmlhttp://www.aygfsteel.com/kxbin/articles/361156.html#Feedback0http://www.aygfsteel.com/kxbin/comments/commentRss/361156.htmlhttp://www.aygfsteel.com/kxbin/services/trackbacks/361156.html阅读全文

kxbin 2011-10-13 15:47 发表评论
]]>
探烦q发~程Q二Q?-----写线E安全的Java代码Q{Q?/title><link>http://www.aygfsteel.com/kxbin/articles/361155.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Thu, 13 Oct 2011 07:37:00 GMT</pubDate><guid>http://www.aygfsteel.com/kxbin/articles/361155.html</guid><wfw:comment>http://www.aygfsteel.com/kxbin/comments/361155.html</wfw:comment><comments>http://www.aygfsteel.com/kxbin/articles/361155.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/kxbin/comments/commentRss/361155.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/kxbin/services/trackbacks/361155.html</trackback:ping><description><![CDATA[<div><span style="color: #333333; font-family: Arial; font-size: 17px; line-height: 25px; "><p>在写JavaE序的时候,何时需要进行ƈ发控Ӟ关键在于判断q段E序或这个类是否是线E安全的?/p><p>当多个线E访问一个类Ӟ如果不用考虑q些U程在运行时环境下的调度和交替执行,q且不需要额外的同步Q这个类的行Z然是正确的,那么U这个类是线E安全的。我们设计类是要在有潜在ƈ发问题存在情况下Q设计线E安全的cR线E安全的cd以通过以下手段来满I</p><ul><li>不跨U程׃n变量</li><li>使状态变量ؓ不可变的</li><li>在Q何访问状态变量的时候用同步?/li><li>每个׃n的可变变量都需要由唯一一个确定的锁保护?/li></ul><p><strong>满U程安全的一些思\</strong></p><p><strong>1Q从源头避免q发问题</strong></p><p>很多开发者一惛_有ƈ发的可能通过底层技术来解决问题Q其实往往可以通过上层的架构设计和业务分析来避免ƈ发场景。比如我们需要用多线E或分布式集来计算一堆客L相关l计|׃客户的统计值是׃n数据Q因此会有ƈ发潜在可能。但从业务上我们可以分析出客户与客户之间数据是不׃n的,因此可以设计一个规则来保证一个客L计算工作和数据访问只会被一个线E或一台工作机完成Q而不是把一个客L计算工作分配l多个线E去完成。这U规则很Ҏ(gu)设计。当你从源头避免了q发问题的可能,下面的工作就完全可以不用担心U程安全问题?/p><p><strong>2Q无状态就是线E安?/strong></p><p>多线E编E或者分布式~程最忌讳有状态,一有状态就不但限制了其横向扩展能力Q也是生ƈ发问题的h。当你设计的cL无状态的Q那么它永远都是U程安全的。因此在设计阶段需要考虑如何用无状态的cL满你的业务需?/p><p><strong>3Q分清原子性操作和复合操作</strong></p><p>所谓原子性,是说一个操作不会被其他U程打断Q能保证其从开始到l束独n资源q箋执行完这一操作。如果所有程序块都是原子性的Q那么就不存在Q何ƈ发问题。而很多看上去像是原子性的操作正式q发问题高灾区。比如所熟知的计数器Qcount++Q和check-then-actQ这些都是很Ҏ(gu)被忽视的Q例如大家所常用的惰性初始化模式Q以下代码就不是U程安全的:</p><p> </p><div nogutter="" bg_java:nogutter:nocontrols"="" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 688px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px; "><div style="padding-left: 0px; "></div><ol start="1" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 0px !important; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; list-style-type: none !important; list-style-position: initial !important; list-style-image: initial !important; background-color: #ffffff; color: #5c5c5c; "><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: none !important; list-style-image: initial !important; list-style-position: initial !important; border-left-width: 0px; background-color: #ffffff; color: inherit; line-height: 25px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-style: initial; border-color: initial; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #646464; background-color: inherit; ">@NotThreadSafe</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">  </span></span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: none !important; list-style-image: initial !important; list-style-position: initial !important; border-left-width: 0px; background-color: #f8f8f8; color: #5c5c5c; line-height: 25px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-style: initial; border-color: initial; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; ">public</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; ">class</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; "> LazyInitRace {  </span></span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: none !important; list-style-image: initial !important; list-style-position: initial !important; border-left-width: 0px; background-color: #ffffff; color: inherit; line-height: 25px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-style: initial; border-color: initial; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">    <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; ">private</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; "> ExpensiveObject instance = </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; ">null</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">;  </span></span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: none !important; list-style-image: initial !important; list-style-position: initial !important; border-left-width: 0px; background-color: #f8f8f8; color: #5c5c5c; line-height: 25px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-style: initial; border-color: initial; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">    <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; ">public</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; "> ExpensiveObject getInstance() {  </span></span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: none !important; list-style-image: initial !important; list-style-position: initial !important; border-left-width: 0px; background-color: #ffffff; color: inherit; line-height: 25px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-style: initial; border-color: initial; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">        <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; ">if</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; "> (instance == </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; ">null</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">)  </span></span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: none !important; list-style-image: initial !important; list-style-position: initial !important; border-left-width: 0px; background-color: #f8f8f8; color: #5c5c5c; line-height: 25px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-style: initial; border-color: initial; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">            instance = <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; ">new</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; "> ExpensiveObject();  </span></span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: none !important; list-style-image: initial !important; list-style-position: initial !important; border-left-width: 0px; background-color: #ffffff; color: inherit; line-height: 25px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-style: initial; border-color: initial; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">        <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; ">return</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; "> instance;  </span></span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: none !important; list-style-image: initial !important; list-style-position: initial !important; border-left-width: 0px; background-color: #f8f8f8; color: #5c5c5c; line-height: 25px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-style: initial; border-color: initial; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">    }  </span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: none !important; list-style-image: initial !important; list-style-position: initial !important; border-left-width: 0px; background-color: #ffffff; color: inherit; line-height: 25px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-style: initial; border-color: initial; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">}  </span></li></ol></div><p> </p><p>q段代码具体问题在于没有认识到if(instance==null)和instance = new ExpensiveObject();是两条语句,攑֜一起就不是原子性的Q就有可能当一个线E执行完if(instance==null)后会被中断,另一个线E也L行if(instance==null)Q这ơ两个线E都会执行后面的instance = new ExpensiveObject();q也是这个程序所不希望发生的?/p><p>虽然check-then-act从表面上看很单,但却普遍存在与我们日常的开发中Q特别是在数据库存取q一块。比如我们需要在数据库里存一个客Ll计|当统计g存在时初始化Q当存在时就L新。如果不把这l逻辑设计为原子性的很有可能生出两条q个客户的统计倹{?/p><p>在单机环境下处理q个问题q算Ҏ(gu)Q通过锁或者同步来把这l复合操作变为原子操作,但在分布式环境下׃适用了。一般情况下是通过在数据库端做文章Q比如通过唯一性烦引或者?zhn)观锁来保障其数据一致性。当然Q何方案都是有代h(hun)的,q就需要具体情况下来权衡?/p><p>另外Qjava1.5以后提供了一套提供原子性操作的c,有兴的可以研究一下它是如何在软g层面保证原子性的?/p><p><strong>4Q锁的合理?/strong></p><p>大家都知道可以用锁来解决q发问题Q但在具体用上q有很多讲究Q比如:</p><ul><li>每个׃n的可变变量都需要由一个个定的锁保护?/li><li>一旦用了锁,意味着q段代码的执行就丧失了操作系l多道程序的Ҏ(gu),会在一定程度上影响性能</li><li>锁不能解军_分布式环境共享变量的q发问题</li></ul></span></div><img src ="http://www.aygfsteel.com/kxbin/aggbug/361155.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/kxbin/" target="_blank">kxbin</a> 2011-10-13 15:37 <a href="http://www.aygfsteel.com/kxbin/articles/361155.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>探烦q发~程Q一Q?-----操作pȝ(转)http://www.aygfsteel.com/kxbin/articles/361153.htmlkxbinkxbinThu, 13 Oct 2011 07:26:00 GMThttp://www.aygfsteel.com/kxbin/articles/361153.htmlhttp://www.aygfsteel.com/kxbin/comments/361153.htmlhttp://www.aygfsteel.com/kxbin/articles/361153.html#Feedback0http://www.aygfsteel.com/kxbin/comments/commentRss/361153.htmlhttp://www.aygfsteel.com/kxbin/services/trackbacks/361153.html阅读全文

kxbin 2011-10-13 15:26 发表评论
]]>
q接数据库的Ҏ(gu)Q从属性文件中dQ?/title><link>http://www.aygfsteel.com/kxbin/articles/358629.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Wed, 14 Sep 2011 08:47:00 GMT</pubDate><guid>http://www.aygfsteel.com/kxbin/articles/358629.html</guid><wfw:comment>http://www.aygfsteel.com/kxbin/comments/358629.html</wfw:comment><comments>http://www.aygfsteel.com/kxbin/articles/358629.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/kxbin/comments/commentRss/358629.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/kxbin/services/trackbacks/358629.html</trackback:ping><description><![CDATA[1.属性文件的内容Q以键值对的Ş式保存)Q?br /><div><div>url=jdbc\:oracle\:thin\:@localhost\:1521\:orcl</div><div>user.name=root</div><div>user.password=root</div><div>driver.class=oracle.jdbc.driver.OracleDriver<br />2.d属性文?br /> package com.srg.china.db;</div><div><div>import java.io.IOException;</div><div>import java.io.InputStream;</div><div>import java.sql.Connection;</div><div>import java.sql.DriverManager;</div><div>import java.sql.SQLException;</div><div>import java.util.Properties;</div><div></div><div>import org.apache.log4j.Logger;</div><div>/**</div><div> * E序功能Q取得数据库的连?/div><div> * @author Administrator</div><div> *</div><div> */</div><div>public class ChinaLogin {</div><div><span style="white-space:pre"> </span>private static Logger log=Logger.getLogger(ChinaLogin.class);</div><div><span style="white-space:pre"> </span>static Properties prop=null;</div><div><span style="white-space:pre"> </span>static String driver;</div><div><span style="white-space:pre"> </span>static String url;</div><div><span style="white-space:pre"> </span>static String user;</div><div><span style="white-space:pre"> </span>static String pwd;</div><div><span style="white-space:pre"> </span>static{</div><div><span style="white-space:pre"> </span>InputStream ins=null;</div><div><span style="white-space:pre"> </span>prop=new Properties();</div><div><span style="white-space:pre"> </span>ins=ChinaLogin.class.getResourceAsStream("./db.properties");</div><div><span style="white-space:pre"> </span>if(null == ins){</div><div><span style="white-space:pre"> </span>log.debug("文g不存?);</div><div><span style="white-space:pre"> </span>}else{</div><div><span style="white-space:pre"> </span>try {</div><div><span style="white-space:pre"> </span>prop.load(ins);</div><div><span style="white-space:pre"> </span>driver=prop.getProperty("driver.class");</div><div><span style="white-space:pre"> </span>url=prop.getProperty("url");</div><div><span style="white-space:pre"> </span>user=prop.getProperty("user.name");</div><div><span style="white-space:pre"> </span>pwd=prop.getProperty("user.password");</div><div><span style="white-space:pre"> </span>} catch (IOException e) {</div><div><span style="white-space:pre"> </span>log.debug(e.getMessage());</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span>}</div><div>//<span style="white-space:pre"> </span>取得数据库的q接</div><div><span style="white-space:pre"> </span>public static Connection getConnection(){</div><div><span style="white-space:pre"> </span>Connection conn=null;</div><div><span style="white-space:pre"> </span></div><div><span style="white-space:pre"> </span>try {</div><div><span style="white-space:pre"> </span>Class.forName(driver);</div><div><span style="white-space:pre"> </span>conn=DriverManager.getConnection(url,user,pwd);</div><div><span style="white-space:pre"> </span>} catch (ClassNotFoundException e) {</div><div><span style="white-space:pre"> </span>log.debug("注册p|"+e.getMessage());</div><div><span style="white-space:pre"> </span>} catch (SQLException e) {</div><div><span style="white-space:pre"> </span>log.debug("q接p|"+e.getMessage());</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span></div><div><span style="white-space:pre"> </span>return conn;</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span></div><div>//<span style="white-space:pre"> </span>试</div><div><span style="white-space:pre"> </span>/*</div><div><span style="white-space:pre"> </span>public static void main(String[] args){</div><div><span style="white-space:pre"> </span>Connection conn=null;</div><div><span style="white-space:pre"> c</span>onn=ChinaLogin.getConnection();</div><div><span style="white-space:pre"> </span>if(conn!=null){</div><div><span style="white-space:pre"> </span>log.debug("成功");</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span>*/</div><div>}</div></div><div></div></div><div></div><img src ="http://www.aygfsteel.com/kxbin/aggbug/358629.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/kxbin/" target="_blank">kxbin</a> 2011-09-14 16:47 <a href="http://www.aygfsteel.com/kxbin/articles/358629.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ͬ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ǭ</a>| <a href="http://" target="_blank">̩</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">IJ</a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">޻</a>| <a href="http://" target="_blank">Դ</a>| <a href="http://" target="_blank">Դ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">˻</a>| <a href="http://" target="_blank">Ĭ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ˮ</a>| <a href="http://" target="_blank">ٹ</a>| <a href="http://" target="_blank">ֺ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ڰ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Т</a>| <a href="http://" target="_blank">ɽ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>