﻿<?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>C++博客-信心比金钱更重要！</title><link>http://www.cppblog.com/luofeng225/</link><description>目标明确==&gt;&gt;&gt;计划跟踪==&gt;&gt;&gt;行动执行！</description><language>zh-cn</language><lastBuildDate>Wed, 08 Apr 2026 01:35:22 GMT</lastBuildDate><pubDate>Wed, 08 Apr 2026 01:35:22 GMT</pubDate><ttl>60</ttl><item><title>TextView 加链接所有方法</title><link>http://www.cppblog.com/luofeng225/archive/2012/05/18/175274.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Fri, 18 May 2012 01:50:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/05/18/175274.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/175274.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/05/18/175274.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/175274.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/175274.html</trackback:ping><description><![CDATA[<a href="http://blog.csdn.net/a54cc/article/details/6447447"><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 12pt; line-height: 30px; font-family: 'Microsoft YaHei'; text-align: left"></a><a style="color: rgb(0,0,0); text-decoration: none" href="http://blog.csdn.net/a54cc/article/details/6447447">TextView 加链接所有方法</a><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">1：使用android:autoLink="all" 只需在textview中加入这个属性 在里面写的文字中包含网址、电话、email的会自动加入连接地址。</span></span><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">2：uses a string resource containing explicit &lt;a&gt; tags to specify<br />links.<br />同时设置<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">textView.setMovementMethod(LinkMovementMethod.getInstance());</span></span><br /></span></span><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">&nbsp;注意格式：&lt;a href<strong>="http://www.google.com</strong>"&gt;link&lt;/a&gt;&nbsp; &nbsp;&#8220;http://&#8221; 不可少。<br /></span></span><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">3： builds the text in the Java code using HTML<br /></span></span><font color="#333333"><font face="Arial">同时设置<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">textView.setMovementMethod(LinkMovementMethod.getInstance());</span></span></font></font><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">4：字符串截取方法 <font color="#333333">SpannableString <br /></font><font color="#333333">同时设置<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">textView.setMovementMethod(LinkMovementMethod.getInstance());</span></span></font><br /><br />SpannableString ss = new SpannableString("text4: Click here to dial the phone.");<br /><br />ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);<br />ss.setSpan(new URLSpan("tel:4155551212"), 13, 17, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);</span></span><br />link<br />ApiDemo <a href="http://blog.csdn.net/a54cc/article/details/6447447"></span></span><br />http://blog.csdn.net/a54cc/article/details/6447447</a><img src ="http://www.cppblog.com/luofeng225/aggbug/175274.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-05-18 09:50 <a href="http://www.cppblog.com/luofeng225/archive/2012/05/18/175274.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>并发基础 www</title><link>http://www.cppblog.com/luofeng225/archive/2012/05/07/173897.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Mon, 07 May 2012 06:14:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/05/07/173897.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/173897.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/05/07/173897.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/173897.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/173897.html</trackback:ping><description><![CDATA[<br />《并发编程实践》<br />-----------------------<br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; line-height: 25px; font-family: Helvetica, Tahoma, Arial, sans-serif; text-align: left"><strong style="font-weight: bold">并发基础</strong><span class="Apple-converted-space">&nbsp;</span><br /><br />编写线程安全的代码, 本质上就是管理对状态的访问,而且通常都是共享的, 可变的状态.<span class="Apple-converted-space">&nbsp;<br /><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; line-height: 25px; font-family: Helvetica, Tahoma, Arial, sans-serif; text-align: left"><strong style="font-weight: bold">竞争条件</strong><span class="Apple-converted-space">&nbsp;</span><br />最常见的一种竞争条件是"检查再运行(check-then-act)", 使用一个潜在的过期值作为下一步操作的依据.<span class="Apple-converted-space">&nbsp;</span><br /><br />检查再运行: 你观察到一些事情为真, 然后基于你的观察去执行一些动作, 但事实上, 从观察到执行操作的这段时间内, 观察结果可能已经无效了, 从而引发错误.<span class="Apple-converted-space">&nbsp;<br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; line-height: 25px; font-family: Helvetica, Tahoma, Arial, sans-serif; text-align: left"><strong style="font-weight: bold">原子操作</strong><span class="Apple-converted-space">&nbsp;</span><br />假设有操作a和b, 如果从执行a的线程的角度看, 当其他线程执行b时, 要么b全部执行完成, 要么一点也没有执行, 那么a和b就互为原子操作.<span class="Apple-converted-space">&nbsp;</span><br /><br />为了保证线程安全, "检查再运行"操作和"读-改-写"操作必须是原子操作.<span class="Apple-converted-space">&nbsp;</span></span></span><br /><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; line-height: 25px; font-family: Helvetica, Tahoma, Arial, sans-serif; text-align: left"><strong style="font-weight: bold">锁的可重入特点</strong><span class="Apple-converted-space">&nbsp;</span><br />线程在试图获得它自己占有的锁时, 请求线程将会成功, 重进入意味着所有的请求都是基于"每线程", 而不是基于"每调用".<span class="Apple-converted-space">&nbsp;<br /></span></span></span><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; line-height: 25px; font-family: Helvetica, Tahoma, Arial, sans-serif; text-align: left"><strong style="font-weight: bold">共享对象</strong><span class="Apple-converted-space">&nbsp;</span><br />同步同样还有一个重要而微妙的方面: 内存可见性. 我们不仅希望能够避免一个线程修改其他线程正在使用的对象的状态, 而且希望确保当一个线程修改了对象的状态之后, 他线程能够真正看到改变.<span class="Apple-converted-space">&nbsp;</span></span></span><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; line-height: 25px; font-family: Helvetica, Tahoma, Arial, sans-serif; text-align: left">锁不仅是关于同步与互斥的, 也是关于内存可见的, 为了保证所有线程都能看到共享的, 可变变量的最新值, 读取和写入线程必须使用公共的锁进行同步.<span class="Apple-converted-space">&nbsp;</span><br /></span></span><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; line-height: 25px; font-family: Helvetica, Tahoma, Arial, sans-serif; text-align: left"><strong style="font-weight: bold">逸出</strong><span class="Apple-converted-space">&nbsp;</span><br />如果一个对象还没有完成构造就发布了, 这种情况就是逸出.</span></span><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; orphans: 2; widows: 2; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; line-height: 25px; font-family: Helvetica, Tahoma, Arial, sans-serif; text-align: left"><strong style="font-weight: bold">死锁</strong><span class="Apple-converted-space">&nbsp;</span><br />当每个人都拥有他人需要的资源, 并且等待其他人正在占有的资源, 如果大家一直占有资源, 直到获得自己需要却没被占用的资源, 那么就会产生死锁.<span class="Apple-converted-space">&nbsp;</span><br />当一个线程永远占有一个锁, 而其他线程尝试去获得这个锁, 那么它们将永远被阻塞. 当线程占有锁L时, 想要获得锁M, 但是同时, 线程B持有M, 并尝试获得L, 两个线程将永远等待下去, 这种情况是死锁的最简单的形式.<span class="Apple-converted-space">&nbsp;</span></span></span><br /><br /><br /><br /></span></span></span></span></span></span><img src ="http://www.cppblog.com/luofeng225/aggbug/173897.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-05-07 14:14 <a href="http://www.cppblog.com/luofeng225/archive/2012/05/07/173897.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>并发编程实践</title><link>http://www.cppblog.com/luofeng225/archive/2012/05/07/173889.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Mon, 07 May 2012 03:58:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/05/07/173889.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/173889.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/05/07/173889.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/173889.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/173889.html</trackback:ping><description><![CDATA[<br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 20px; font-family: 'Microsoft YaHei', Verdana, Tahoma, Arial, Helvetica, sans-serif">1, 保证线程安全的三种方法 :<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />a, 不要跨线程访问共享变量<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />b, 使共享变量是 final类型的<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />c, 将共享变量的操作加上同步<br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 20px; font-family: 'Microsoft YaHei', Verdana, Tahoma, Arial, Helvetica, sans-serif">2, 一开始就将类设计成线程安全的 , 比在后期重新修复它 ,更容易 .</span></span><br /><br />编写多线程程序, 首先保证它是正确的, 其次再考虑性能.<br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 20px; font-family: 'Microsoft YaHei', Verdana, Tahoma, Arial, Helvetica, sans-serif">7, 对于 volatile 声明的数值类型变量进行运算 , 往往是不安全的 (volatile 只能保证可见性 , 不能保证原子性 ).<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />详见 volatile 原理与技巧中 , 脏数据问题讨论 .<br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 20px; font-family: 'Microsoft YaHei', Verdana, Tahoma, Arial, Helvetica, sans-serif"><strong style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">8, 当一个线程请求获得它自己占有的锁时 ( 同一把锁的嵌套使用 ), 我们称该锁为可重入锁 .<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />在 jdk1.5 并发包中 , 提供了可重入锁的 java 实现 -ReentrantLock.<br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 20px; font-family: 'Microsoft YaHei', Verdana, Tahoma, Arial, Helvetica, sans-serif">10,虽然缩小同步块的范围 , 可以提升系统性能 .<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />但在保证原子性的情况下 , 不可将原子操作分解成多个 synchronized块<span class="Apple-converted-space">&nbsp;<br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 20px; font-family: 'Microsoft YaHei', Verdana, Tahoma, Arial, Helvetica, sans-serif"><br /><strong>15, 发布 (publish) 对象 , 指的是使它能够被当前范围之外的代码所使用 .( 引用传递 )<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />对象逸出 (escape), 指的是一个对象在尚未准备好时将它发布 .<br /></strong>&nbsp;原则: 为防止逸出, 对象必须要被完全构造完后, 才可以被发布(最好的解决方式是采用同步) 
<p>&nbsp;&nbsp;&nbsp; this关键字引用对象逸出</p>
<p>&nbsp;&nbsp;&nbsp; 例子: 在构造函数中, 开启线程, 并将自身对象this传入线程, 造成引用传递.而此时, 构造函数尚未执行完, 就会发生对象逸出了.<br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 20px; font-family: 'Microsoft YaHei', Verdana, Tahoma, Arial, Helvetica, sans-serif">16, 必要时 , 使用 ThreadLocal变量确保线程封闭性 (封闭线程往往是比较安全的 , 但一定程度上会造成性能损耗 )<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />封闭对象的例子在实际使用过程中 , 比较常见 , 例如 hibernate openSessionInView机制 , jdbc的 connection机制<span class="Apple-converted-space">&nbsp;<br /></span></span></span><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 20px; font-family: 'Microsoft YaHei', Verdana, Tahoma, Arial, Helvetica, sans-serif"><strong style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">18, 保证共享变量的发布是安全的<span class="Apple-converted-space">&nbsp;</span></strong><br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />a, 通过静态初始化器初始化对象 (jls 12.4.2 叙述 , jvm 会保证静态初始化变量是同步的 )<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />b, 将对象申明为 volatile 或使用 AtomicReference<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />c, 保证对象是不可变的<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />d, 将引用或可变操作都由锁来保护</span></span><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 20px; font-family: 'Microsoft YaHei', Verdana, Tahoma, Arial, Helvetica, sans-serif"></p>
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 10px; padding-top: 0px">9, 设计线程安全的类 , 应该包括的基本要素 :<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />a, 确定哪些是可变共享变量<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />b, 确定哪些是不可变的变量<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />c, 指定一个管理并发访问对象状态的策略</p>
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 10px; padding-top: 0px"><strong style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">20, 将数据封装在对象内部 , 并保证对数据的访问是原子的 .</strong><br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />建议采用 volatile javabean 模型或者构造同步的 getter,setter.</p>
<p><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 20px; font-family: 'Microsoft YaHei', Verdana, Tahoma, Arial, Helvetica, sans-serif">22, 编写并发程序 , 需要更全的注释 , 更完整的文档说明 .<br /><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 20px; font-family: 'Microsoft YaHei', Verdana, Tahoma, Arial, Helvetica, sans-serif"></p>
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 10px; padding-top: 0px">3, 在需要细分锁的分配时 , 使用 java监视器模式好于使用自身对象的监视器锁 .<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />前者的灵活性更好 .</p>
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 10px; padding-top: 0px">Object target = new Object();<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />// 这里使用外部对象来作为监视器 , 而非 this<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />synchronized(target) {<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />// TODO<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />}</p>
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 10px; padding-top: 0px">针对 java monitor pattern, 实际上 ReentrantLock的实现更易于并发编程 .<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />功能上 , 也更强大 .</p>
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 10px; padding-top: 0px">24,<span class="Apple-converted-space">&nbsp;</span><strong style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">设计并发程序时 , 在保证伸缩性与性能折中的前提下 , 优先考虑将共享变量委托给线程安全的类 .<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />由它来控制全局的并发访问 .</strong></p>
<p><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 20px; font-family: 'Microsoft YaHei', Verdana, Tahoma, Arial, Helvetica, sans-serif"></p>
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 10px; padding-top: 0px"><strong style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">26, 在并发编程中 , 需要容器支持的时候 , 优先考虑使用 jdk 并发容器<span class="Apple-converted-space">&nbsp;</span></strong><br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />(ConcurrentHashMap, ConcurrentLinkedQueue, CopyOnWriteArrayList&#8230;).</p>
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 10px; padding-top: 0px">27, ConcurrentHashMap, CopyOnWriteArrayList<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />并发容器的迭代器 , 以及全范围的 size(), isEmpty() 都表现出弱一致性 .<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />他们只能标示容器当时的一个数据状态 . 无法完整响应容器之后的变化和修改<span class="Apple-converted-space">&nbsp;</span></p>
<p><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 20px; font-family: 'Microsoft YaHei', Verdana, Tahoma, Arial, Helvetica, sans-serif"></p>
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 10px; padding-top: 0px">29, 当一个方法 , 能抛出 InterruptedException, 则意味着 , 这个方法是一个可阻塞的方法 , 如果它被中断 , 将提前结束阻塞状态 .<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />当你调用一个阻塞方法 , 也就意味着 , 本身也称为了一个阻塞方法 , 因为你必须等待阻塞方法返回 .</p>
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 10px; padding-top: 0px">如果阻塞方法抛出了中断异常 , 我们需要做的是 , 将其往上层抛 , 除非当前已经是需要捕获异常的层次 .<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />如果当前方法 , 不能抛出 InterruptedException, 可以使用 Thread.currentThread.interrupt() 方法 , 手动进行中断<br /></p>
<p><a href="http://java.chinaitlab.com/advance/824034.html"><br />======================<br />http://java.chinaitlab.com/advance/824034.html</a><br /><a href="http://kenwublog.com/category/concurrency">http://kenwublog.com/category/concurrency</a></span></span></span></span></span></span></span></span></span></span></p></span></span></span></span></span></strong></span></span></span></span></span></span> <img src ="http://www.cppblog.com/luofeng225/aggbug/173889.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-05-07 11:58 <a href="http://www.cppblog.com/luofeng225/archive/2012/05/07/173889.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>BroadcastReceiver</title><link>http://www.cppblog.com/luofeng225/archive/2012/05/07/173884.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Mon, 07 May 2012 03:01:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/05/07/173884.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/173884.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/05/07/173884.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/173884.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/173884.html</trackback:ping><description><![CDATA[<a href="http://blog.csdn.net/liuhe688/article/details/6955668">http://blog.csdn.net/liuhe688/article/details/6955668</a><br /><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">
<p><strong>BroadcastReceiver</strong>也就是&#8220;广播接收者&#8221;的意思，顾名思义，它就是用来接收来自系统和应用中的广播。</p>
<p>在Android系统中，广播体现在方方面面，例如当开机完成后系统会产生一条广播，接收到这条广播就能实现开机启动服务的功能；当网络状态改变时系统会产生一条广播，接收到这条广播就能及时地做出提示和保存数据等操作；当电池电量改变时，系统会产生一条广播，接收到这条广播就能在电量低时告知用户及时保存进度，等等。</p></span><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">&nbsp; 
<p><strong>静态注册</strong><br /></p>
<p>静态注册是在AndroidManifest.xml文件中配置的，注意，这种方式的注册是常驻型的，也就是说当应用关闭后，如果有广播信息传来，MyReceiver也会被系统调用而自动运行。<br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"></p>
<p><strong>动态注册</strong></p>
<p>动态注册需要在代码中动态的指定广播地址并注册，通常我们是在Activity或Service注册一个广播》<br />注意，registerReceiver是android.content.ContextWrapper类中的方法，Activity和Service都继承了ContextWrapper，所以可以直接调用。在实际应用中，我们在Activity或Service中注册了一个BroadcastReceiver，当这个Activity或Service被销毁时如果没有解除注册，系统会报一个异常，提示我们是否忘记解除注册了。所以，记得在特定的地方执行解除注册操作：<br /><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><strong><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"></p>
<p><strong>普通广播（Normal Broadcast）<br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-weight: bold; font-size: 14px; color: rgb(44,44,44); line-height: 28px; font-family: 宋体, 'Arial Narrow', arial, serif">用<span class="Apple-converted-space">&nbsp;</span><font style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" color="#0000ff"><code style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Context.sendBroadcast</code>()</font>发送</span></span></strong></p>
<p>普通广播对于多个接收者来说是完全异步的，通常每个接收者都无需等待即可以接收到广播，接收者相互之间不会有影响。对于这种广播，接收者无法终止广播，即无法阻止其他接收者的接收动作。<br /></p>
<p></span><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"></p>
<p><strong><br />有序广播（Ordered Broadcast）<br /></strong></p>
<p><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-weight: bold; font-size: 14px; color: rgb(44,44,44); line-height: 28px; font-family: 宋体, 'Arial Narrow', arial, serif">用<span class="Apple-converted-space">&nbsp;</span><code style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><font style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" color="#0000ff">Context.sendOrderedBroadcast()</font></code>发送</span></span>有序广播比较特殊，它每次只发送到优先级较高的接收者那里，然后由优先级高的接受者再传播到优先级低的接收者那里，优先级高的接收者有能力终止这个广播。<br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-weight: bold; font-size: 14px; color: rgb(44,44,44); line-height: 28px; font-family: 宋体, 'Arial Narrow', arial, serif"><u>运行的顺序可以通过matched intent-filter 里面的android:priority来控制，当priority优先级相同的时候，Receiver以任意的顺序运行。<br /></u></span></span></p>
<p></span><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(44,44,44); line-height: 28px; font-family: 宋体, 'Arial Narrow', arial, serif"><strong style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><font style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" color="#0000ff"><br /><br />Permission权限</font></strong><br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />&nbsp; 要接收某些action，需要在AndroidManifest.xml里面添加相应的permission。例如接收SMS:<br /></span></span><br />===============<br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(44,44,44); line-height: 28px; font-family: 宋体, 'Arial Narrow', arial, serif"></p>
<div style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">小结：</div>
<ul><li>
<div style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">. 推荐使用显式指明receiver，在配置文件AndroidManifest.xml指明；&nbsp;<br />. 每次接收广播都会重新生成一个接收广播的对象，再次调用onReceive；</div></li><li>
<div style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">. 在BroadCast 中尽量不要处理太多逻辑问题，建议复杂的逻辑交给Activity 或者 Service 去处理。</div></li></ul></span></span>
<p><br /><br />========================<br />利用Application动态注册 和 androidMenifeist.xml静态注册区别<br />退出程序，利用Application动态注册收不到广播。<br /><br /><br /><br /></p></strong></span></span></span><img src ="http://www.cppblog.com/luofeng225/aggbug/173884.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-05-07 11:01 <a href="http://www.cppblog.com/luofeng225/archive/2012/05/07/173884.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>android 电源管理</title><link>http://www.cppblog.com/luofeng225/archive/2012/05/02/173451.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Wed, 02 May 2012 03:49:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/05/02/173451.html</guid><description><![CDATA[<span style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span style="font-size: 12px; color: rgb(59,59,59); line-height: 21px; font-family: Arial, 宋体, sans-serif">
<p style="word-break: break-all" align="left"><span style="word-break: break-all; font-family: 宋体"><span style="font-size: medium">应用层的使用</span></span><span style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span style="font-size: medium">:</span></span></span></p>
<p style="word-break: break-all" align="left"><span style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span style="font-size: medium">Android</span></span></span><span style="word-break: break-all; font-family: 宋体"><span style="font-size: medium">提供了现成</span></span><span style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span style="font-size: medium">android.os.PowerManager</span></span></span><span style="word-break: break-all; font-family: 宋体"><span style="font-size: medium">类</span></span><span style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span style="font-size: medium">,</span></span></span><span style="word-break: break-all; font-family: 宋体"><span style="font-size: medium">该类用于控制设备的电源状态的切换</span></span><span style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span style="font-size: medium">.</span></span></span></p></span></span><br />代码：<br />
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">PowerManager&nbsp;pm&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(PowerManager)&nbsp;getSystemService(Context.POWER_SERVICE);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />&nbsp;PowerManager.WakeLock&nbsp;wl&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">My&nbsp;Tag</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />&nbsp;wl.acquire();<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;..screen&nbsp;will&nbsp;stay&nbsp;on&nbsp;during&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">&nbsp;section..<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />&nbsp;wl.release();</span></div><br /><br />权限要求：<br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 13px; color: rgb(51,51,51); font-family: arial, sans-serif"><font face="Courier New"><font size="4"><font color="#ff0000">&nbsp;&nbsp;<span class="Apple-style-span" style="font-size: medium">&lt;uses-permission android:name=</span></font></font><font color="#ff0000"><em style="word-break: break-all"><span class="Apple-style-span" style="font-size: medium">"android.permission.WAKE_LOCK"</span></em><span class="Apple-style-span" style="font-size: medium">&nbsp;/&gt;</span></font></font> 
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; word-break: break-all; text-indent: 18pt" align="left"><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">&lt;uses-permission android:name=</span><em style="word-break: break-all"><span class="Apple-style-span" style="font-size: medium">"android.permission.DEVICE_POWER"</span></em><span class="Apple-style-span" style="font-size: medium">&nbsp;/&gt;</span></span></p><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 12px; color: rgb(59,59,59); line-height: 21px; font-family: Arial, 宋体, sans-serif; text-align: left">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; word-break: break-all" align="left"><span lang="EN-US" style="color: red; word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span class="Apple-style-span" style="font-size: medium"><br /></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; word-break: break-all" align="left"><span lang="EN-US" style="color: red; word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span class="Apple-style-span" style="font-size: medium"></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; word-break: break-all; text-align: left" align="left"><span style="color: red; word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">注意：<br />所有的锁必须成对的使用</span></span><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">,</span></span><span style="color: red; word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">如果申请了而没有及时释放会造成系统故障</span></span><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">.</span></span><span style="color: red; word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">如申请了</span></span><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">partial wakelock,</span></span><span style="color: red; word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">而没有及时释放</span></span><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">,</span></span><span style="color: red; word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">那系统就永远进不了</span></span><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">Sleep</span></span><span style="color: red; word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">模式</span></span><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">.</span></span></p></span></span></span></span><br /><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 12px; color: rgb(59,59,59); line-height: 21px; font-family: Arial, 宋体, sans-serif"><span lang="EN-US" style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span class="Apple-style-span" style="font-size: medium">Android framework</span></span></span><span style="word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">层面|<br /></span></span><span lang="EN-US" style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span class="Apple-style-span" style="font-size: medium">》》》》<br /><a href="http://www.cnblogs.com/jacktu/archive/2010/07/07/1773011.html">http://www.cnblogs.com/jacktu/archive/2010/07/07/1773011.html</a><br />&nbsp;Linux</span></span></span><span style="word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">内核层面</span></span></span></span> <img src ="http://www.cppblog.com/luofeng225/aggbug/173451.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-05-02 11:49 <a href="http://www.cppblog.com/luofeng225/archive/2012/05/02/173451.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>strlen</title><link>http://www.cppblog.com/luofeng225/archive/2012/04/28/173040.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Sat, 28 Apr 2012 06:36:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/04/28/173040.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/173040.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/04/28/173040.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/173040.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/173040.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; line-height: 25px; font-family: arial, 宋体, sans-serif; text-align: left"><br />strlen所作的仅仅是一个计数器的工作，它从内存的某个位置（可以是字符串开头，中间某个位置，甚至是某个不确定的内存区域）开始扫描，<strong>直到碰到第一个字符串结束符'\0'为止</strong>，然后返回计数器值。<br /><br />通常用于字符串长度获得。<br /><br />其他byte数据，用这个测量len，可能中间有\0 ??<br /></span></span><img src ="http://www.cppblog.com/luofeng225/aggbug/173040.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-04-28 14:36 <a href="http://www.cppblog.com/luofeng225/archive/2012/04/28/173040.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>硬链接和符号链接(软链接) 彻底理解</title><link>http://www.cppblog.com/luofeng225/archive/2012/04/27/172888.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Fri, 27 Apr 2012 01:02:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/04/27/172888.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/172888.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/04/27/172888.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/172888.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/172888.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); text-indent: 28px; line-height: 25px; font-family: Verdana, Helvetica, Arial, sans-serif"><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); text-indent: 28px; line-height: 25px; font-family: Verdana, Helvetica, Arial, sans-serif">&nbsp;<br />&nbsp;&nbsp; Linux 文件系统最重要的特点之一是它的文件链接。链接是对文件的引用，这样您可以让文件在文件系统中多处被看到。保存在磁盘分区中的文件不管是什么类型都给它分配一个编号，称为索引节点号inode 。在 Linux 中，链接可以如同原始文件一样来对。链接可以与普通的文件一样被执行、编辑和访问。对系统中的其他应用程序而言，链接就是它所对应的原始文件。当您通过链接对文件进行编辑时，您编辑的实际上是原始文件。<br />链接不是副本。有两种类型的链接：硬链接和符号链接(软链接)。&nbsp;</span></span><br />&nbsp;<br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); text-indent: 28px; line-height: 25px; font-family: Verdana, Helvetica, Arial, sans-serif"><strong>硬链接只</strong>能引用同一文件系统中的文件。它引用的是文件在文件系统中的物理索引(也称为 inode)。当您移动或删除原始文件时，硬链接不会被破坏，因为<strong>它所引用的是文件的物理数据而不是文件在文件结构中的位置</strong>。硬链接的文件不需要用户有访问原始文件的权限，也不会显示原始文件的位置，这样有助于文件的安全。如果您删除的文件有相应的硬链接，那么这个文件依然会保留，直到所有对它的引用都被删除。<strong><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(65,73,71); text-indent: 28px; font-family: Arial; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">一个文件除非链接数为0，否则不会物理地从文件系统中被删除。</span></span><br /></strong><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); text-indent: 28px; line-height: 25px; font-family: Verdana, Helvetica, Arial, sans-serif">&nbsp;&nbsp; <br /><strong>软连接</strong>，其实就是新建立一个文件，这个文件就是专门用来指向别的文件的（那就和windows 下的快捷方式的那个文件有很接近的意味）。软连接产生的是一个新的文件，但这个文件的作用就是专门指向某个文件的，删了这个软连接文件，那就等于不需要这个连接，和原来的存在的实体原文件没有任何关系，但删除原来的文件，则相应的软连接不可用（cat那个软链接文件，则提示&#8220;没有该文件或目录&#8220;）。</span></span></span></span></span></span> <br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 25px; font-family: Verdana, Helvetica, Arial, sans-serif">
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 6px; word-break: break-all; text-indent: 2em; padding-top: 0px"><br /><strong>硬链接与软链接的区别；<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; word-break: break-all; padding-top: 0px" /></strong><u>&nbsp;&nbsp;&nbsp; 硬连接是不会建立inode的，他只是在文件原来的inode link count域再增加1而已，</u>也因此硬链接是不可以跨越文件系统的。相反都是软连接会重新建立一个inode，当然inode的结构跟其他的不一样，他只是一个指明源文件的字符串信息。一旦删除源文件，那么软连接将变得毫无意义。而硬链接删除的时候，系统调用会检查inode link count的数值，如果他大于等于1，那么inode不会被回收。因此文件的内容不会被删除。<br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 25px; font-family: Verdana, Helvetica, Arial, sans-serif">&nbsp; <br />　硬链接实际上是为文件建一个别名，链接文件和原文件实际上是同一个文件。可以通过ls -i来查看一下，这两个文件的inode号是同一个，说明它们是同一个文件；而软链接建立的是一个指向，即链接文件内的内容是指向原文件的指针，它们是两个文件。&nbsp;<span class="Apple-converted-space">&nbsp;</span><br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; word-break: break-all; padding-top: 0px" />&nbsp;　　软链接可以跨文件系统，硬链接不可以；软链接可以对一个不存在的文件名(filename)进行链接（当然此时如果你vi这个软链接文件，linux会自动新建一个文件名为filename的文件）,硬链接不可以（其文件必须存在，inode必须存在）；软链接可以对目录进行连接，硬链接不可以。</p>
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 6px; word-break: break-all; text-indent: 2em; padding-top: 0px"></span></span><br /><br />创建<br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); text-indent: 28px; line-height: 25px; font-family: Verdana, Helvetica, Arial, sans-serif">两种链接都可以通过命令 ln 来创建。ln 默认创建的是硬链接。使用 -s 开关可以创建软链接。</span></span><br /><br />格式：ln 文件&nbsp; 链接文件<br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 25px; font-family: Verdana, Helvetica, Arial, sans-serif">&nbsp;创建的硬链接文件与原文件的文件大小相同，node值相同。文件属性为普通文件。</p>
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 6px; word-break: break-all; text-indent: 2em; padding-top: 0px">当修改任意个文件内容均可是三个文件内容同时改变。<br /></span></span><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); text-indent: 28px; line-height: 25px; font-family: Verdana, Helvetica, Arial, sans-serif">当删除原文件的时候硬链接文件仍然存在，且内容不变。<br /></span></span><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(65,73,71); text-indent: 28px; font-family: Arial; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;对硬链接有如下限制：<br style="line-height: normal" />&nbsp;&nbsp;&nbsp;&nbsp; &#9670;不能对目录文件做硬链接。<br style="line-height: normal" />&nbsp;&nbsp;&nbsp;&nbsp; &#9670;不能在不同的文件系统之间做硬链接。也就是说,链接文件和被链接文件必须位于同一个文件系统中。</span></span><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); text-indent: 28px; line-height: 25px; font-family: Verdana, Helvetica, Arial, sans-serif">[guo@guo ~]$ ln -s link link.back1&nbsp;<span class="Apple-converted-space">&nbsp;</span><br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; word-break: break-all; padding-top: 0px" />[guo@guo ~]$ ls -al |grep 'link*'&nbsp;<span class="Apple-converted-space">&nbsp;<br /><br /></span></span></span><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); text-indent: 28px; line-height: 25px; font-family: Verdana, Helvetica, Arial, sans-serif">注意此时链接的文件属性为l，软文件大小与原文件大小也不一样。node值不一样！<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; word-break: break-all; padding-top: 0px" />&nbsp;<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; word-break: break-all; padding-top: 0px" />与硬链接一样，当修改任意个文件内容均可是三个文件内容同时改变，此处不在举例。&nbsp;<br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; word-break: break-all; padding-top: 0px" />对于软链接当删除原文件后链接文件不能再打开。</span></span><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(65,73,71); line-height: 27px; font-family: Arial; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">符号链接没有硬链接的限制，可以对目录文件做符号链接，也可以在不同文件系统之间做符号链接。</p>
<p style="text-indent: 2em; line-height: normal">&nbsp;<strong>&nbsp;用&#8220;ln -s&#8221;命令建立符号链接时，最好源文件用绝对路径名</strong>，这样可以在任何工作目录下进行符号链接。当源文件用相对路径时，如果当前的工作路径和你要创建的符号链接文件所在路径不同时，就不能进行链接</p>
<p style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px 0px 6px; word-break: break-all; text-indent: 2em; padding-top: 0px"></span></span><br /><br /><a href="http://www.hx95.com/Article/Tech/201204/54204.html">http://www.hx95.com/Article/Tech/201204/54204.html</a><br /></p></span></span><img src ="http://www.cppblog.com/luofeng225/aggbug/172888.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-04-27 09:02 <a href="http://www.cppblog.com/luofeng225/archive/2012/04/27/172888.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jni记录</title><link>http://www.cppblog.com/luofeng225/archive/2012/04/26/172851.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Thu, 26 Apr 2012 11:35:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/04/26/172851.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/172851.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/04/26/172851.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/172851.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/172851.html</trackback:ping><description><![CDATA[&nbsp;<br /> JNI技术的出现主要是基于三个方面的应用需求： 
<p><font size="3">1. 解决性能问题</font><font size="3"><br />2. 解决本机平台接口调用问题<br />3. 嵌入式开发应用<br /><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 13px; font-family: 'Microsoft YaHei', Verdana, Tahoma, 'Lucida Grande', Arial, sans-serif"><strong>生成头文件&nbsp;</strong>
<p style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 10px; line-height: 23px; padding-top: 0px; border-right-width: 0px">可以用javah命令来自动生成JNI的头文件，这样可以省事很多的，进入命令行，切换到项目的bin目录下，执行命令：</p>
<blockquote style="border-right: rgb(191,223,255) 1px dashed; padding-right: 10px; border-top: rgb(191,223,255) 1px dashed; padding-left: 10px; padding-bottom: 10px; margin: 10px 0px; border-left: rgb(191,223,255) 1px dashed; padding-top: 10px; border-bottom: rgb(191,223,255) 1px dashed; background-color: rgb(245,251,255); background-origin: initial; background-clip: initial">
<p style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 10px; line-height: 23px; padding-top: 0px; border-right-width: 0px"><strong style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px; border-right-width: 0px">javah -classpath . -jni 包.类名</strong></p></blockquote>
<p style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 10px; line-height: 23px; padding-top: 0px; border-right-width: 0px">命令执行完以后会在bin目录下面生成一.h头文件，然后将该.h头文件拷贝到你要编写的C/C++目录下面去吧。<br /><br /><strong>方法签名<br /></strong><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 13px; color: rgb(51,51,51); line-height: 17px; font-family: verdana, sans-serif; border-collapse: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px"><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 13px; color: rgb(51,51,51); line-height: 17px; font-family: verdana, sans-serif; border-collapse: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">使用JNI在native内调用java方法时，需要知道java方法的方法签名，利用javap工具可以方便的生成签名。由于java方法签名在jni层的表示方法的复杂性，利用这个工具生成签名信息可以避免人工分析带来的错误。</span></span><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 13px; color: rgb(51,51,51); line-height: 17px; font-family: verdana, sans-serif; border-collapse: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">javap -s -p -classpath .<span class="Apple-converted-space">&nbsp;<strong>类名<br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 13px; color: rgb(51,51,51); line-height: 17px; font-family: verdana, sans-serif; border-collapse: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">-s表示打印签名信息<br />-p表示打印所有函数和成员的签名信息，默认只打印public的签名信息。<br />注意：<br />粗体部分是.class文件的文件名，不要.class后缀，<br /><br />必备资料：<br />jni手册<br /><br /><br /></span></span></strong></span></span></span></span></span></span></span></font></p> <img src ="http://www.cppblog.com/luofeng225/aggbug/172851.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-04-26 19:35 <a href="http://www.cppblog.com/luofeng225/archive/2012/04/26/172851.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C编程常遇问题</title><link>http://www.cppblog.com/luofeng225/archive/2012/04/26/172829.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Thu, 26 Apr 2012 08:12:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/04/26/172829.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/172829.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/04/26/172829.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/172829.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/172829.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(98,91,73); font-family: Arial; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px"><br /><strong><br />expected specifier-qualifier-list before sth之类得编译错误，<br /></strong>造成这种错误得主要原因就是使用了未被定义的变量。关于specifier-qualifier-list的定义：<span style="line-height: normal">It's a list of specifiers and qualifiers :-) Specifiers are things like&nbsp;<code style="line-height: normal">void</code>,&nbsp;<code style="line-height: normal">char</code>,&nbsp;<code style="line-height: normal">struct Foo</code>, etc., and qualifiers are keywords like&nbsp;<code style="line-height: normal">const</code>&nbsp;and&nbsp;<code style="line-height: normal">volatile</code>. See&nbsp;<a style="font-size: 12px; color: rgb(98,91,73); line-height: normal; text-decoration: underline" href="http://www.lysator.liu.se/c/ANSI-C-grammar-y.html#specifier-qualifier-list" rel="nofollow">this C grammar</a>&nbsp;for the definition</span></span></span> <br /><br /><strong><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; line-height: 25px; font-family: arial, 宋体, sans-serif"><strong>Malloc</strong> 向系统申请分配指定size个字节的内存空间。返回类型是 void* 类型。void* 表示未确定类型的指针。C,C++规定，void* 类型可以<a style="color: rgb(19,110,194); text-decoration: underline" href="http://baike.baidu.com/view/965170.htm" target="_blank">强制转换</a>为任何其它类型的指针。<br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; line-height: 24px; font-family: arial, 宋体, sans-serif">原型：extern void *malloc(unsigned int num_bytes);</span></span><br />&nbsp;num_bytes需保证为正数，不然总会返回NULL。<br /><br /><br /><strong>定义指针，必须初始化，否则其值不定是什么值！！<br /></strong>BYTE * pData = NULL;//文本</span></span></strong> <br /><br /><br />函数声明缺少符号&#8220;；&#8221;<br /> <img src ="http://www.cppblog.com/luofeng225/aggbug/172829.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-04-26 16:12 <a href="http://www.cppblog.com/luofeng225/archive/2012/04/26/172829.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>#include "" 和 #include &lt;&gt; 区别</title><link>http://www.cppblog.com/luofeng225/archive/2012/04/26/172828.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Thu, 26 Apr 2012 08:08:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/04/26/172828.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/172828.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/04/26/172828.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/172828.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/172828.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; line-height: 23px; font-family: simsun; text-align: left"><br /><br />include &nbsp; " "是先从本地目录开始寻找，然后去寻找系统路径<span class="Apple-converted-space">&nbsp;</span><br />而Include &nbsp; &lt;&gt; &nbsp; 相反先从系统目录，后从本地目录<span class="Apple-converted-space">&nbsp;</span><br />你的问题应该还是路径的问题，检查下工程设置里面的引入路径</span></span> <br /><br /><br /><a href="http://blog.chinaunix.net/uid-26183957-id-3162472.html">http://blog.chinaunix.net/uid-26183957-id-3162472.html</a><img src ="http://www.cppblog.com/luofeng225/aggbug/172828.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-04-26 16:08 <a href="http://www.cppblog.com/luofeng225/archive/2012/04/26/172828.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>