﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-上善若水-随笔分类-收藏</title><link>http://www.blogjava.net/DLevin/category/50406.html</link><description>In general the OO style is to use a lot of little objects with a lot of little methods that give us a lot of plug points for overriding and variation.
To do is to be -Nietzsche, To bei is to do -Kant, Do be do be do -Sinatra</description><language>zh-cn</language><lastBuildDate>Sat, 05 Sep 2015 04:44:37 GMT</lastBuildDate><pubDate>Sat, 05 Sep 2015 04:44:37 GMT</pubDate><ttl>60</ttl><item><title>[转]高性能IO模型浅析</title><link>http://www.blogjava.net/DLevin/archive/2015/09/04/427118.html</link><dc:creator>DLevin</dc:creator><author>DLevin</author><pubDate>Fri, 04 Sep 2015 07:16:00 GMT</pubDate><guid>http://www.blogjava.net/DLevin/archive/2015/09/04/427118.html</guid><wfw:comment>http://www.blogjava.net/DLevin/comments/427118.html</wfw:comment><comments>http://www.blogjava.net/DLevin/archive/2015/09/04/427118.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/DLevin/comments/commentRss/427118.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/DLevin/services/trackbacks/427118.html</trackback:ping><description><![CDATA[<h1 id="reader-title">高性能IO模型浅析</h1><p>转自：http://www.cnblogs.com/fanzhidongyzby/p/4098546.html</p><p><span>服务器端编程经常需要构造高性能的IO模型，常见的IO模型有四种：</span></p><p><span>（1）</span><span>同步阻塞IO（Blocking&nbsp;IO）：即传统的IO模型。</span></p><p><span>（2）</span><span>同步非阻塞</span><span>IO（Non-blocking&nbsp;IO）：默认创建的socket都是阻塞的，非阻塞IO要求socket被设置为NONBLOCK。注意这里所说的NIO并非Java的NIO（New&nbsp;IO）库。</span></p><p><span>（3）</span><span>IO多路复用（IO&nbsp;Multiplexing）：即经典的Reactor设计模式，有时也称为异步阻塞IO，Java中的Selector和Linux中的epoll都是这种模型。</span></p><p><span>（4）</span><span>异步IO（Asynchronous&nbsp;IO）：即经典的Proactor设计模式，也称为异步非阻塞IO。</span></p><p><span>同步和异步</span><span>的概念描述的是用户线程与内核的交互方式：同步是指用户线程发起IO请求后需要等待或者轮询内核IO操作完成后才能继续执行；而异步是指用户线程发起IO请求后仍继续执行，当内核IO操作完成后会通知用户线程，或者调用用户线程注册的回调函数。</span></p><p><span>阻塞和非阻塞</span><span>的概念描述的是用户线程调用内核IO操作的方式：阻塞是指IO操作需要彻底完成后才返回到用户空间；而非阻塞是指IO操作被调用后立即返回给用户一个状态值，无需等到IO操作彻底完成。</span></p><p><span>另外，</span><span>Richard&nbsp;Stevens</span><span>&nbsp;在《Unix&nbsp;网络编程》卷1中提到的基于信号驱动的IO（Signal&nbsp;Driven&nbsp;IO）模型，由于该模型并不常用，本文不作涉及。接下来，我们详细分析四种常见的IO模型的实现原理。为了方便描述，我们统一使用IO的读操作作为示例。</span></p><p><span>一、</span><span>同步阻塞IO</span></p><p><span>同步阻塞IO模型是最简单的IO模型，用户线程在内核进行IO操作时被阻塞。</span></p><p><img src="http://images.cnitblog.com/blog/405877/201411/142330286789443.png" alt="" height="285" width="535" /></p><p><span>图</span><span>1&nbsp;同步阻塞IO</span></p><p><span>如图1所示，用户线程通过系统调用read发起IO读操作，由用户空间转到内核空间。内核等到数据包到达后，然后将接收的数据拷贝到用户空间，完成read操作。</span></p><p><span>用户线程使用同步阻塞IO模型的伪代码描述为：</span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">{<br />&nbsp;&nbsp;&nbsp;&nbsp;read(socket,&nbsp;buffer);<br />&nbsp;&nbsp;&nbsp;&nbsp;process(buffer);<br />}</span></div><p><span>即用户需要等待read将socket中的数据读取到buffer后，才继续处理接收的数据。整个IO请求的过程中，用户线程是被阻塞的，这导致用户在发起IO请求时，不能做任何事情，对CPU的资源利用率不够。</span></p><p><span>二、</span><span>同步非阻塞IO</span></p><p><span>同步非阻塞IO是在同步阻塞IO的基础上，将socket设置为NONBLOCK。这样做用户线程可以在发起IO请求后可以立即返回。</span></p><p>&nbsp;<img src="http://images.cnitblog.com/blog/405877/201411/142332004602984.png" alt="" height="315" width="562" /></p><p><span>图2&nbsp;同步非阻塞IO</span></p><p><span>如图2所示，由于socket是非阻塞的方式，因此用户线程发起IO请求时立即返回。但并未读取到任何数据，用户线程需要不断地发起IO请求，直到数据到达后，才真正读取到数据，继续执行。</span></p><p><span>用户线程使用同步非阻塞IO模型的伪代码描述为：</span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">(read(socket,&nbsp;buffer)&nbsp;</span><span style="color: #000000; ">!=</span><span style="color: #000000; ">&nbsp;SUCCESS) { }<br />&nbsp;&nbsp;&nbsp;&nbsp;process(buffer);<br />}</span></div><p><span>即
用户需要不断地调用read，尝试读取socket中的数据，直到读取成功后，才继续处理接收的数据。整个IO请求的过程中，虽然用户线程每次发起IO请
求后可以立即返回，但是为了等到数据，仍需要不断地轮询、重复请求，消耗了大量的CPU的资源。一般很少直接使用这种模型，而是在其他IO模型中使用非阻
塞IO这一特性。</span></p><p><span>三、</span><span>IO多路复用</span></p><p><span>IO多路复用模型是建立在内核提供的多路分离函数select基础之上的，使用select函数可以避免同步非阻塞IO模型中轮询等待的问题。</span></p><p><img src="http://images.cnitblog.com/blog/405877/201411/142332187256396.png" alt="" height="320" width="539" /></p><p><span>图3&nbsp;多路分离函数select</span></p><p><span>如图3所示，用户首先将需要进行IO操作的socket添加到select中，然后阻塞等待select系统调用返回。当数据到达时，socket被激活，select函数返回。用户线程正式发起read请求，读取数据并继续执行。</span></p><p><span>从
流程上来看，使用select函数进行IO请求和同步阻塞模型没有太大的区别，甚至还多了添加监视socket，以及调用select函数的额外操作，效
率更差。但是，使用select以后最大的优势是用户可以在一个线程内同时处理多个socket的IO请求。用户可以注册多个socket，然后不断地调
用select读取被激活的socket，即可达到在</span><span>同一个线程内同时处理多个IO请求的目的</span><span>。而在同步阻塞模型中，必须通过多线程的方式才能达到这个目的。</span></p><p><span>用户线程使用select函数的伪代码描述为：</span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">{<br />&nbsp;&nbsp;&nbsp;&nbsp;select(socket);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">(</span><span style="color: #000000; ">1</span><span style="color: #000000; ">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sockets&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;select();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">for</span><span style="color: #000000; ">(socket&nbsp;</span><span style="color: #0000FF; ">in</span><span style="color: #000000; ">&nbsp;sockets)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(can_read(socket))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read(socket,&nbsp;buffer);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;process(buffer);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</span></div><p><span>其中while循环前将socket添加到select监视中，然后在while内一直调用select获取被激活的socket，一旦socket可读，便调用read函数将socket中的数据读取出来。</span></p><p><span>然
而，使用select函数的优点并不仅限于此。虽然上述方式允许单线程内处理多个IO请求，但是每个IO请求的过程还是阻塞的（在select函数上阻
塞），平均时间甚至比同步阻塞IO模型还要长。如果用户线程只注册自己感兴趣的socket或者IO请求，然后去做自己的事情，等到数据到来时再进行处
理，则可以提高CPU的利用率。</span></p><p><span>IO多路复用模型使用了Reactor设计模式实现了这一机制。</span></p><p><img src="http://images.cnitblog.com/blog/405877/201411/142332350853195.png" alt="" height="185" width="567" /></p><p><span>图4&nbsp;Reactor设计模式</span></p><p><span>如
图4所示，EventHandler抽象类表示IO事件处理器，它拥有IO文件句柄Handle（通过get_handle获取），以及对Handle的
操作handle_event（读/写等）。继承于EventHandler的子类可以对事件处理器的行为进行定制。Reactor类用于管理
EventHandler（注册、删除等），并使用handle_events实现事件循环，不断调用同步事件多路分离器（一般是内核）的多路分离函数
select，只要某个文件句柄被激活（可读/写等），select就返回（阻塞），handle_events就会调用与文件句柄关联的事件处理器的
handle_event进行相关操作。</span></p><p><img src="http://images.cnitblog.com/blog/405877/201411/142333254136604.png" alt="" height="300" width="647" /></p><p><span>图</span><span>5&nbsp;IO多路复用</span></p><p><span>如
图5所示，通过Reactor的方式，可以将用户线程轮询IO操作状态的工作统一交给handle_events事件循环进行处理。用户线程注册事件处理
器之后可以继续执行做其他的工作（异步），而Reactor线程负责调用内核的select函数检查socket状态。当有socket被激活时，则通知
相应的用户线程（或执行用户线程的回调函数），执行handle_event进行数据读取、处理的工作。由于select函数是阻塞的，因此多路IO复用
模型也被称为异步阻塞IO模型。注意，这里的所说的阻塞是指select函数执行时线程被阻塞，而不是指socket。一般在使用IO多路复用模型
时，socket都是设置为NONBLOCK的，不过这并不会产生影响，因为用户发起IO请求时，数据已经到达了，用户线程一定不会被阻塞。</span></p><p><span>用户线程使用IO多路复用模型的伪代码描述为：</span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;UserEventHandler::handle_event()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(can_read(socket))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read(socket,&nbsp;buffer);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;process(buffer);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;Reactor.register(</span><span style="color: #0000FF; ">new</span><span style="color: #000000; ">&nbsp;UserEventHandler(socket));<br />}</span></div><p><span>用户需要重写EventHandler的handle_event函数进行读取数据、处理数据的工作，用户线程只需要将自己的EventHandler注册到Reactor即可。Reactor中handle_events事件循环的伪代码大致如下。</span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">Reactor::handle_events()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">(</span><span style="color: #000000; ">1</span><span style="color: #000000; ">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sockets&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;select();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">for</span><span style="color: #000000; ">(socket&nbsp;</span><span style="color: #0000FF; ">in</span><span style="color: #000000; ">&nbsp;sockets)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get_event_handler(socket).handle_event();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</span></div><p><span>事件循环不断地调用select获取被激活的socket，然后根据获取socket对应的EventHandler，执行器handle_event函数即可。</span></p><p><span>IO多路复用是最常使用的IO模型，但是其异步程度还不够&#8220;彻底&#8221;，因为它使用了会阻塞线程的select系统调用。因此IO多路复用只能称为异步阻塞IO，而非真正的异步IO。</span></p><p><span>四、</span><span>异步IO</span></p><p><span>&#8220;真
正&#8221;的异步IO需要操作系统更强的支持。在IO多路复用模型中，事件循环将文件句柄的状态事件通知给用户线程，由用户线程自行读取数据、处理数据。而在异
步IO模型中，当用户线程收到通知时，数据已经被内核读取完毕，并放在了用户线程指定的缓冲区内，内核在IO完成后通知用户线程直接使用即可。</span></p><p><span>异步IO模型使用了Proactor设计模式实现了这一机制。</span></p><p><img src="http://images.cnitblog.com/blog/405877/201411/151608309061672.jpg" alt="" height="248" width="744" /></p><p><span>图6&nbsp;Proactor设计模式</span></p><p><span>如
图6，Proactor模式和Reactor模式在结构上比较相似，不过在用户（Client）使用方式上差别较大。Reactor模式中，用户线程通过
向Reactor对象注册感兴趣的事件监听，然后事件触发时调用事件处理函数。而Proactor模式中，用户线程将
AsynchronousOperation（读/写等）、Proactor以及操作完成时的CompletionHandler注册到
AsynchronousOperationProcessor。AsynchronousOperationProcessor使用Facade模式提
供了一组异步操作API（读/写等）供用户使用，当用户线程调用异步API后，便继续执行自己的任务。
AsynchronousOperationProcessor&nbsp;会开启独立的内核线程执行异步操作，实现真正的异步。当异步IO操作完成
时，AsynchronousOperationProcessor将用户线程与AsynchronousOperation一起注册的Proactor
和CompletionHandler取出，然后将CompletionHandler与IO操作的结果数据一起转发给
Proactor，Proactor负责回调每一个异步操作的事件完成处理函数handle_event。虽然Proactor模式中每个异步操作都可以
绑定一个Proactor对象，但是一般在操作系统中，Proactor被实现为Singleton模式，以便于集中化分发操作完成事件。</span></p><p><img src="http://images.cnitblog.com/blog/405877/201411/142333511475767.png" alt="" height="297" width="686" /></p><p><span>图</span><span>7&nbsp;异步IO</span></p><p><span>如
图7所示，异步IO模型中，用户线程直接使用内核提供的异步IO&nbsp;API发起read请求，且发起后立即返回，继续执行用户线程代码。不过此时用户线程已
经将调用的AsynchronousOperation和CompletionHandler注册到内核，然后操作系统开启独立的内核线程去处理IO操
作。当read请求的数据到达时，由内核负责读取socket中的数据，并写入用户指定的缓冲区中。最后内核将read的数据和用户线程注册的
CompletionHandler分发给内部Proactor，Proactor将IO完成的信息通知给用户线程（一般通过调用用户线程注册的完成事件
处理函数），完成异步IO。</span></p><p><span>用户线程使用异步IO模型的伪代码描述为：</span></p><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;UserCompletionHandler::handle_event(buffer)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;process(buffer);<br />}<br /><br />{<br />&nbsp;&nbsp;&nbsp; aio_read(socket,&nbsp;</span><span style="color: #0000FF; ">new</span><span style="color: #000000; ">&nbsp;UserCompletionHandler);<br />}</span></div><p><span>用户需要重写CompletionHandler的handle_event函数进行处理数据的工作，参数buffer表示Proactor已经准备好的数据，用户线程直接调用内核提供的异步IO&nbsp;API，并将重写的CompletionHandler注册即可。</span></p><p><span>相
比于IO多路复用模型，异步IO并不十分常用，不少高性能并发服务程序使用IO多路复用模型+多线程任务处理的架构基本可以满足需求。况且目前操作系统对
异步IO的支持并非特别完善，更多的是采用IO多路复用模型模拟异步IO的方式（IO事件触发时不直接通知用户线程，而是将数据读写完毕后放到用户指定的
缓冲区中）。Java7之后已经支持了异步IO，感兴趣的读者可以尝试使用。</span></p><p><span>本文从基本概念、工作流程和代码示
例三个层次简要描述了常见的四种高性能IO模型的结构和原理，理清了同步、异步、阻塞、非阻塞这些容易混淆的概念。通过对高性能IO模型的理解，可以在服
务端程序的开发中选择更符合实际业务特点的IO模型，提高服务质量。希望本文对你有所帮助。</span></p><p><br /><span></span></p><p><span>相似的：<br />http://www.cnblogs.com/nufangrensheng/p/3588690.html<br />http://www.ibm.com/developerworks/cn/linux/l-async/<br /></span></p><img src ="http://www.blogjava.net/DLevin/aggbug/427118.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/DLevin/" target="_blank">DLevin</a> 2015-09-04 15:16 <a href="http://www.blogjava.net/DLevin/archive/2015/09/04/427118.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]HotSpot术语表</title><link>http://www.blogjava.net/DLevin/archive/2015/08/10/426721.html</link><dc:creator>DLevin</dc:creator><author>DLevin</author><pubDate>Mon, 10 Aug 2015 12:27:00 GMT</pubDate><guid>http://www.blogjava.net/DLevin/archive/2015/08/10/426721.html</guid><wfw:comment>http://www.blogjava.net/DLevin/comments/426721.html</wfw:comment><comments>http://www.blogjava.net/DLevin/archive/2015/08/10/426721.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/DLevin/comments/commentRss/426721.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/DLevin/services/trackbacks/426721.html</trackback:ping><description><![CDATA[<p>非常好的术语参考表，纪录下来以防以后忘了。转自：<a href="http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html">http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html</a><br /><br /></p><h1 style="font-size: 12.5pt; padding: 0pt; margin: 0ex 0.5ex 1ex 0pt; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Luxi Sans', Verdana, Arial, Helvetica;">HotSpot Glossary of Terms</h1><p style="padding: 0pt; margin: 1ex 0em; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Luxi Sans', Verdana, Arial, Helvetica; font-size: 13.3333330154419px; line-height: 18.6666660308838px;">A work in progress, especially as the HotSpot VM evolves. But a place to put definitions of things so we only have to define them once. There are empty entries (marked&nbsp;<em>TBD</em>&nbsp;for "to be defined") because we think of things that we need to define faster than we think of good definitions.</p><dl style="font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Luxi Sans', Verdana, Arial, Helvetica; font-size: 13.3333330154419px; line-height: 18.6666660308838px;"><dt><a name="adaptiveSpinning" id="adaptiveSpinning"><strong>adaptive spinning</strong></a></dt><dd>An optimization technique whereby a thread spins waiting for a change-of-state to occur (typically a flag that represents some event has occurred - such as the release of a lock) rather than just blocking until notified that the change has occurred. The "adaptive" part comes from the policy decisions that control how long the thread will spin until eventually deciding to block.</dd><dt><a name="biasedLocking" id="biasedLocking"><strong>biased locking</strong></a></dt><dd>An optimization in the VM that leaves an object as logically locked by a given thread even after the thread has released the lock. The premise is that if the thread subsequently reacquires the lock (as often happens), then reacquisition can be achieved at very low cost. If a different thread tries to acquire a biased lock then the bias must be revoked from the current bias owner.</dd><dt><a name="blockStartTable" id="blockStartTable"><strong>block start table</strong></a></dt><dd>A table that shows, for a region of the heap, where the object starts that comes on to this region from lower addresees. Used, for example, with the<a href="http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html#cardTable" style="text-decoration: none; color: #666666;">card table</a>&nbsp;variant of the&nbsp;<a href="http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html#rememberedSet" style="text-decoration: none; color: #666666;">remembered set</a>.</dd><dt><a name="bootstrapClassloader" id="bootstrapClassloader"><strong>bootstrap classloader</strong></a></dt><dd>The logical classloader that has responsibility for loading the classes (and resources) that are found in the boot-classpath - typically the core Java platform classes. Typically implemented as part of the VM, by historical convention the bootstrap classloader is represented by NULL at the Java API level.</dd><dt><a name="bytecodeVerification" id="bytecodeVerification"><strong>bytecode verification</strong></a></dt><dd>A step in the linking process of a class where the methods bytecodes are analyzed to ensure type-safety.</dd><dt><a name="C1Compiler" id="C1Compiler"><strong>C1 compiler</strong></a></dt><dd>Fast, lightly optimizing bytecode compiler. Performs some value numbering, inlining, and class analysis. Uses a simple CFG-oriented SSA "high" IR, a machine-oriented "low" IR, a linear scan register allocation, and a template-style code generator.</dd><dt><a name="C2Compiler" id="C2Compiler"><strong>C2 compiler</strong></a></dt><dd>Highly optimizing bytecode compiler, also known as 'opto'. Uses a "sea of nodes" SSA "ideal" IR, which lowers to a machine-specific IR of the same kind. Has a graph-coloring register allocator; colors all machine state, including local, global, and argument registers and stack. Optimizations include global value numbering, conditional constant type propagation, constant folding, global code motion, algebraic identities, method inlining (aggressive, optimistic, and/or multi-morphic), intrinsic replacement, loop transformations (unswitching, unrolling), array range check elimination.</dd><dt><a name="cardTable" id="cardTable"><strong>card table</strong></a></dt><dd>A kind of&nbsp;<a href="http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html#rememberedSet" style="text-decoration: none; color: #666666;">remembered set</a>&nbsp;that records where oops have changed in a generation.</dd><dt><a name="classDataSharing" id="classDataSharing"><strong>class data sharing</strong></a></dt><dd>A startup optimization that records the in-memory form of some classes, so that that form can be mapped into memory by a subsequent run of the virtual machine, rather than loading those classes from their class files.</dd><dt><a name="classHierachyAnalysis" id="classHierachyAnalysis"><strong>class hierachy analysis</strong></a></dt><dd>Also known as 'CHA'. Analysis of the class tree used by a compiler to determine if the receiver at a virtual call site has a single implementor. If so, the callee can be inlined or the compiler can employ some other static call mechanism.</dd><dt><a name="codeCache" id="codeCache"><strong>code cache</strong></a></dt><dd>A special heap that holds compiled code. These objects are not relocated by the GC, but may contain oops, which serve as GC roots.</dd><dt><a name="compaction" id="compaction"><strong>compaction</strong></a></dt><dd>A garbage collection technique that results in live objects occupying a dense portion of the virtual address space, and available space in another portion of the address space. Cf.&nbsp;<a href="http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html#freeList" style="text-decoration: none; color: #666666;">free list</a>.</dd><dt><a name="concurrency" id="concurrency"><strong>concurrency</strong></a></dt><dd>Concurrency, or more specifically concurrent programming, is the logical simultaneous execution of multiple instruction streams. If multiple processors are available then the logical simultaneity can be physical simultaneity - this is known as 'parallelism'</dd><dt><a name="concurrentGarbageCollection" id="concurrentGarbageCollection"><strong>concurrent garbage collection</strong></a></dt><dd>A garbage collection algorithm that does most (if not all) of its work while the Java application threads are still running.</dd><dt><a name="copyingGarbageCollection" id="copyingGarbageCollection"><strong>copying garbage collection</strong></a></dt><dd>A garbage collection algorithm that moves objects during the collection.</dd><dt><a name="deoptimization" id="deoptimization"><strong>deoptimization</strong></a></dt><dd>The process of converting an compiled (or more optimized) stack frame into an interpreted (or less optimized) stack frame. Also describes the discarding of an nmethod whose dependencies (or other assumptions) have been broken. Deoptimized nmethods are typically recompiled to adapt to changing application behavior. Example: A compiler initially assumes a reference value is never null, and tests for it using a trapping memory access. Later on, the application uses null values, and the method is deoptimized and recompiled to use an explicit test-and-branch idiom to detect such nulls.</dd><dt><a name="dependency" id="dependency"><strong>dependency</strong></a></dt><dd>An optimistic assumption associated with an nmethod, which allowed the compiler to emit improved code into the nmethod. Example: A given class has no subclasses, which simplifies method dispatch and type testing. The loading of new classes (or replacement of old classes) can cause dependencies to become false, which requires dependent nmethods to be discarded and activations of those nmethods to be deoptimized.</dd><dt><a name="eden" id="eden"><strong>eden</strong></a></dt><dd>A part of the Java object heap where object can be created efficiently.</dd><dt><a name="freeList" id="freeList"><strong>free list</strong></a></dt><dd>A storage management technique in which unused parts of the Java object heap are chained one to the next, rather than having all of the unused part of the heap in a single block.</dd><dt><a name="garbageCollection" id="garbageCollection"><strong>garbage collection</strong></a></dt><dd>The automatic management of storage.</dd><dt><a name="garbageCollectionRoot" id="garbageCollectionRoot"><strong>garbage collection root</strong></a></dt><dd>A pointer into the Java object heap from outside the heap. These come up, e.g., from static fields of classes, local references in activation frames, etc.</dd><dt><a name="GCMap" id="GCMap"><strong>GC map</strong></a></dt><dd>A description emitted by the JIT (C1 or C2) of the locations of oops in registers or on stack in a compiled stack frame. Each code location which might execute a safepoint has an associated GC map. The GC knows how to parse a frame from a stack, to request a GC map from a frame's nmethod, and to unpack the GC map and manage the indicated oops within the stack frame.</dd><dt><a name="generationalGarbageCollection" id="generationalGarbageCollection"><strong>generational garbage collection</strong></a></dt><dd>A storage management technique that separates objects expected to be referenced for different lengths of time into different regions of the heap, so that different algorithms can be applied to the collection of those regions.</dd><dt><a name="handle" id="handle"><strong>handle</strong></a></dt><dd>A memory word containing an oop. The word is known to the GC, as a root reference. C/C++ code generally refers to oops indirectly via handles, to enable the GC to find and manage its root set more easily. Whenever C/C++ code blocks in a safepoint, the GC may change any oop stored in a handle. Handles are either 'local' (thread-specific, subject to a stack discipline though not necessarily on the thread stack) or global (long-lived and explicitly deallocated). There are a number of handle implementations throughout the VM, and the GC knows about them all.</dd><dt><a name="hotLock" id="hotLock"><strong>hot lock</strong></a></dt><dd>A lock that is highly contended.</dd><dt><a name="interpreter" id="interpreter"><strong>interpreter</strong></a></dt><dd>A VM module which implements method calls by individually executing bytecodes. The interpreter has a limited set of highly stylized stack frame layouts and register usage patterns, which it uses for all method activations. The Hotspot VM generates its own interpreter at start-up time.</dd><dt><a name="JITCompilers" id="JITCompilers"><strong>JIT compilers</strong></a></dt><dd>An on-line compiler which generates code for an application (or class library) during execution of the application itself. ("JIT" stands for "just in time".) A JIT compiler may create machine code shortly before the first invocation of a Java method. Hotspot compilers usually allow the interpreter ample time to "warm up" Java methods, by executing them thousands of times. This warm-up period allows a compiler to make better optimization decisions, because it can observe (after initial class loading) a more complete class hierarchy. The compiler can also inspect branch and type profile information gathered by the interpreter.</dd><dt><a name="JNI" id="JNI"><strong>JNI</strong></a></dt><dd>The Java Native Interface - a specification and API for how Java code can call out to native C code, and how native C code can call into the Java VM</dd><dt><a name="JVMTI" id="JVMTI"><strong>JVM TI</strong></a></dt><dd>The Java Virtual Machine Tools Interface - a standard specification and API that is used by development and monitoring tools. See&nbsp;<a href="http://openjdk.java.net/groups/hotspot/docs/Serviceability.html#tjvmti" style="text-decoration: none; color: #666666;">JVM TI</a>&nbsp;for more information.</dd><dt><a name="klassPointer" id="klassPointer"><strong>klass pointer</strong></a></dt><dd>The second word of every object header. Points to another object (a metaobject) which describes the layout and behavior of the original object. For Java objects, the "klass" contains a C++ style "vtable".</dd><dt><a name="markWord" id="markWord"><strong>mark word</strong></a></dt><dd>The first word of every object header. Usually a set of bitfields including synchronization state and identity hash code. May also be a pointer (with characteristic low bit encoding) to synchronization related information. During GC, may contain GC state bits.</dd><dt><a name="nmethod" id="nmethod"><strong>nmethod</strong></a></dt><dd>A block of executable code which implements some Java bytecodes. It may be a complete Java method, or an 'OSR' method. It routinely includes object code for additional methods inlined by the compiler.</dd><dt><a name="objectHeader" id="objectHeader"><strong>object header</strong></a></dt><dd>Common structure at the beginning of every GC-managed heap object. (Every oop points to an object header.) Includes fundamental information about the heap object's layout, type, GC state, synchronization state, and identity hash code. Consists of two words. In arrays it is immediately followed by a length field. Note that both Java objects and VM-internal objects have a common object header format.</dd><dt><a name="objectPromotion" id="objectPromotion"><strong>object promotion</strong></a></dt><dd>The act of copying an object from one generation to another.</dd><dt><a name="oldGeneration" id="oldGeneration"><strong>old generation</strong></a></dt><dd>A region of the Java object heap that holds object that have remained referenced for a while.</dd><dt><a name="onStackReplacement" id="onStackReplacement"><strong>on-stack replacement</strong></a></dt><dd>Also known as 'OSR'. The process of converting an interpreted (or less optimized) stack frame into a compiled (or more optimized) stack frame. This happens when the interpreter discovers that a method is looping, requests the compiler to generate a special nmethod with an entry point somewhere in the loop (specifically, at a backward branch), and transfers control to that nmethod. A rough inverse to deoptimization.</dd><dt><a name="oop" id="oop"><strong>oop</strong></a></dt><dd>An object pointer. Specifically, a pointer into the GC-managed heap. (The term is traditional. One 'o' may stand for 'ordinary'.) Implemented as a native machine address, not a handle. Oops may be directly manipulated by compiled or interpreted Java code, because the GC knows about the liveness and location of oops within such code. (See GC map.) Oops can also be directly manipulated by short spans of C/C++ code, but must be kept by such code within handles across every safepoint.</dd><dt><a name="parallelClassloading" id="parallelClassloading"><strong>parallel classloading</strong></a></dt><dd>The ability to have multiple classes/type be in the process of being loaded by the same classloader at the same time.</dd><dt><a name="parallelGarbageCollection" id="parallelGarbageCollection"><strong>parallel garbage collection</strong></a></dt><dd>A garbage collection algorithm that uses multiple threads of control to perform more efficiently on multi-processor boxes.</dd><dt><a name="permanentGeneration" id="permanentGeneration"><strong>permanent generation</strong></a></dt><dd>A region of the address space that holds object allocated by the virtual machine itself, but which is managed by the garbage collector. The permanent generation is mis-named, in that almost all of the objects in it&nbsp;<em>can</em>be collected, though they tend to be referenced for a long time, so they rarely become garbage.</dd><dt><a name="rememberedSet" id="rememberedSet"><strong>remembered set</strong></a></dt><dd>A data structure that records pointers between generations.</dd><dt><a name="safepoint" id="safepoint"><strong>safepoint</strong></a></dt><dd>A point during program execution at which all GC roots are known and all heap object contents are consistent. From a global point of view, all threads must block at a safepoint before the GC can run. (As a special case, threads running JNI code can continue to run, because they use only handles. During a safepoint they must block instead of loading the contents of the handle.) From a local point of view, a safepoint is a distinguished point in a block of code where the executing thread may block for the GC. Most call sites qualify as safepoints. There are strong invariants which hold true at every safepoint, which may be disregarded at non-safepoints. Both compiled Java code and C/C++ code be optimized between safepoints, but less so across safepoints. The JIT compiler emits a GC map at each safepoint. C/C++ code in the VM uses stylized macro-based conventions (e.g., TRAPS) to mark potential safepoints.</dd><dt><a name="seaOfNodes" id="seaOfNodes"><strong>sea-of-nodes</strong></a></dt><dd>The high-level intermediate representation in C2. It is an SSA form where both data and control flow are represented with explicit edges between nodes. It differs from forms used in more traditional compilers in that nodes are not bound to a block in a control flow graph. The IR allows nodes to float within the sea (subject to edge constraints) until they are scheduled late in the compilation process.</dd><dt><a name="sa" id="sa"><strong>Serviceability Agent (SA)</strong></a></dt><dd>The Serviceablity Agent is collection of Sun internal code that aids in debugging HotSpot problems. It is also used by several JDK tools - jstack, jmap, jinfo, and jdb. See&nbsp;<a href="http://openjdk.java.net/groups/hotspot/docs/Serviceability.html#tsa" style="text-decoration: none; color: #666666;">SA</a>&nbsp;for more information.</dd><dt><a name="stackmap" id="stackmap"><strong>stackmap</strong></a></dt><dd>Refers to the StackMapTable attribut e or a particular StackMapFrame in the table.</dd><dt><a name="StackMapTable" id="StackMapTable"><strong>StackMapTable</strong></a></dt><dd>An attribute of the Code attribute in a classfile which contains type information used by the new verifier during verification. It consists of an array of StackMapFrames. It is generated automatically by javac as of JDK6.</dd><dt><a name="survivorSpace" id="survivorSpace"><strong>survivor space</strong></a></dt><dd>A region of the Java object heap used to hold objects. There are usually a pair of survivor spaces, and collection of one is achieved by copying the referenced objects in one survivor space to the other survivor space.</dd><dt><a name="synchronization" id="synchronization"><strong>synchronization</strong></a></dt><dd>In general terms this is the coordination of concurrent activities to ensure the safety and liveness properties of those activities. For example, protecting access to shared data by using a lock to guard all code paths to that data.</dd><dt><a name="TLAB" id="TLAB"><strong>TLAB</strong></a></dt><dd>Thread-local allocation buffer. Used to allocate heap space quickly without synchronization. Compiled code has a "fast path" of a few instructions which tries to bump a high-water mark in the current thread's TLAB, successfully allocating an object if the bumped mark falls before a TLAB-specific limit address.</dd><dt><a name="uncommonTrap" id="uncommonTrap"><strong>uncommon trap</strong></a></dt><dd>When code generated by C2 reverts back to the interpreter for further execution. C2 typically compiles for the common case, allowing it to focus on optimization of frequently executed paths. For example, C2 inserts an uncommon trap in generated code when a class that is uninitialized at compile time requires run time initialization.</dd><dt><a name="verifier" id="verifier"><strong>verifier</strong></a></dt><dd>The software code in the VM which performs bytecode verification.</dd><dt><a name="VMOperations" id="VMOperations"><strong>VM Operations</strong></a></dt><dd>Operations in the VM that can be requested by Java threads, but which must be executed, in serial fashion by a specific thread known as the VM thread. These operations are often synchronous, in that the requester will block until the VM thread has completed the operation. Many of these operations also require that the VM be brought to a safepoint before the operation can be performed - a garbage collection request is a simple example.</dd><dt><a name="writeBarrier" id="writeBarrier"><strong>write barrier</strong></a></dt><dd>Code that is executed on every oop store. For example, to maintain a remembered set.</dd><dt><a name="youngGeneration" id="youngGeneration"><strong>young generation</strong></a></dt><dd>A region of the Java object heap that holds recently-allocated objects.</dd></dl><img src ="http://www.blogjava.net/DLevin/aggbug/426721.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/DLevin/" target="_blank">DLevin</a> 2015-08-10 20:27 <a href="http://www.blogjava.net/DLevin/archive/2015/08/10/426721.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]自旋锁、排队自旋锁、MCS锁、CLH锁</title><link>http://www.blogjava.net/DLevin/archive/2015/08/07/416102.html</link><dc:creator>DLevin</dc:creator><author>DLevin</author><pubDate>Thu, 06 Aug 2015 16:18:00 GMT</pubDate><guid>http://www.blogjava.net/DLevin/archive/2015/08/07/416102.html</guid><wfw:comment>http://www.blogjava.net/DLevin/comments/416102.html</wfw:comment><comments>http://www.blogjava.net/DLevin/archive/2015/08/07/416102.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/DLevin/comments/commentRss/416102.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/DLevin/services/trackbacks/416102.html</trackback:ping><description><![CDATA[转自：http://coderbee.net/index.php/concurrent/20131115/577<br /><br /><h3>自旋锁（Spin lock）</h3><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;">自旋锁是指当一个线程尝试获取某个锁时，如果该锁已被其他线程占用，就一直循环检测锁是否被释放，而不是进入线程挂起或睡眠状态。</p><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;">自旋锁适用于锁保护的临界区很小的情况，临界区很小的话，锁占用的时间就很短。</p><h4>简单的实现</h4><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">import</span><span style="color: #000000; ">&nbsp;java.util.concurrent.atomic.AtomicReference;<br /><br /></span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">class</span><span style="color: #000000; ">&nbsp;SpinLock&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">private</span><span style="color: #000000; ">&nbsp;AtomicReference</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">Thread</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">&nbsp;owner&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">new</span><span style="color: #000000; ">&nbsp;AtomicReference</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">Thread</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">();<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;lock()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread&nbsp;currentThread&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;Thread.currentThread();</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;如果锁未被占用，则设置当前线程为锁的拥有者</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">&nbsp;(owner.compareAndSet(</span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">,&nbsp;currentThread))&nbsp;{&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;unlock()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread&nbsp;currentThread&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;Thread.currentThread();</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;只有锁的拥有者才能释放锁</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;owner.compareAndSet(currentThread,&nbsp;</span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</span></div><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;"><br />SimpleSpinLock里有一个owner属性持有锁当前拥有者的线程的引用，如果该引用为null，则表示锁未被占用，不为null则被占用。</p><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;">这里用AtomicReference是为了使用它的原子性的compareAndSet方法（CAS操作），解决了多线程并发操作导致数据不一致的问题，确保其他线程可以看到锁的真实状态<br /></p><h4>缺点</h4><ol style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; list-style-position: outside; list-style-image: initial; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;"><li style="margin: 0px 0px 0px 2.571428571rem; padding: 0px; border: 0px; vertical-align: baseline;">CAS操作需要硬件的配合；</li><li style="margin: 0px 0px 0px 2.571428571rem; padding: 0px; border: 0px; vertical-align: baseline;">保证各个CPU的缓存（L1、L2、L3、跨CPU Socket、主存）的数据一致性，通讯开销很大，在多处理器系统上更严重；</li><li style="margin: 0px 0px 0px 2.571428571rem; padding: 0px; border: 0px; vertical-align: baseline;">没法保证公平性，不保证等待进程/线程按照FIFO顺序获得锁。</li></ol><h3>Ticket Lock</h3><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;">Ticket Lock 是为了解决上面的公平性问题，类似于现实中银行柜台的排队叫号：锁拥有一个服务号，表示正在服务的线程，还有一个排队号；每个线程尝试获取锁之前先拿一个排队号，然后不断轮询锁的当前服务号是否是自己的排队号，如果是，则表示自己拥有了锁，不是则继续轮询。</p><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;">当线程释放锁时，将服务号加1，这样下一个线程看到这个变化，就退出自旋。</p><h4>简单的实现</h4><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">import</span><span style="color: #000000; ">&nbsp;java.util.concurrent.atomic.AtomicInteger;&nbsp;&nbsp;<br /><br /></span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">class</span><span style="color: #000000; ">&nbsp;TicketLock&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">private</span><span style="color: #000000; ">&nbsp;AtomicInteger&nbsp;serviceNum&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">new</span><span style="color: #000000; ">&nbsp;AtomicInteger();&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;服务号</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">private</span><span style="color: #000000; ">&nbsp;AtomicInteger&nbsp;ticketNum&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">new</span><span style="color: #000000; ">&nbsp;AtomicInteger();&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;排队号</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;lock()&nbsp;{&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;首先原子性地获得一个排队号</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;myTicketNum&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;ticketNum.getAndIncrement();&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;只要当前服务号不是自己的就不断轮询</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">&nbsp;(serviceNum.get()&nbsp;</span><span style="color: #000000; ">!=</span><span style="color: #000000; ">&nbsp;myTicketNum)&nbsp;{&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;myTicketNum;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;unlock(</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;myTicket)&nbsp;{&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;只有当前线程拥有者才能释放锁</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;next&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;myTicket&nbsp;</span><span style="color: #000000; ">+</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">1</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serviceNum.compareAndSet(myTicket,&nbsp;next);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</span></div><h4>缺点</h4><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;">Ticket Lock 虽然解决了公平性的问题，但是多处理器系统上，每个进程/线程占用的处理器都在读写同一个变量serviceNum ，每次读写操作都必须在多个处理器缓存之间进行缓存同步，这会导致繁重的系统总线和内存的流量，大大降低系统整体的性能。</p><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;">下面介绍的CLH锁和MCS锁都是为了解决这个问题的。</p><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;">MCS 来自于其发明人名字的首字母： John Mellor-Crummey和Michael Scott。</p><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;">CLH的发明人是：Craig，Landin and Hagersten。</p><h3>MCS锁</h3><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;">MCS Spinlock 是一种基于链表的可扩展、高性能、公平的自旋锁，申请线程只在本地变量上自旋，直接前驱负责通知其结束自旋，从而极大地减少了不必要的处理器缓存同步的次数，降低了总线和内存的开销。</p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">import</span><span style="color: #000000; ">&nbsp;java.util.concurrent.atomic.AtomicReferenceFieldUpdater;<br /><br /></span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">class</span><span style="color: #000000; ">&nbsp;MCSLock&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">static</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">class</span><span style="color: #000000; ">&nbsp;MCSNode&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">volatile</span><span style="color: #000000; ">&nbsp;MCSNode&nbsp;next;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">volatile</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">boolean</span><span style="color: #000000; ">&nbsp;isBlock&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">true</span><span style="color: #000000; ">;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;默认是在等待锁</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">volatile</span><span style="color: #000000; ">&nbsp;MCSNode&nbsp;queue;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;指向最后一个申请锁的MCSNode</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">private</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">static</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">final</span><span style="color: #000000; ">&nbsp;AtomicReferenceFieldUpdater&nbsp;UPDATER&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;AtomicReferenceFieldUpdater<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.newUpdater(MCSLock.</span><span style="color: #0000FF; ">class</span><span style="color: #000000; ">,&nbsp;MCSNode.</span><span style="color: #0000FF; ">class</span><span style="color: #000000; ">,&nbsp;</span><span style="color: #000000; ">"</span><span style="color: #000000; ">queue</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;lock(MCSNode&nbsp;currentThread)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MCSNode&nbsp;predecessor&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;UPDATER.getAndSet(</span><span style="color: #0000FF; ">this</span><span style="color: #000000; ">,&nbsp;currentThread);</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;step&nbsp;1</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">&nbsp;(predecessor&nbsp;</span><span style="color: #000000; ">!=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;predecessor.next&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;currentThread;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;step&nbsp;2</span><span style="color: #008000; "><br /></span><span style="color: #000000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">&nbsp;(currentThread.isBlock)&nbsp;{</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;step&nbsp;3</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;unlock(MCSNode&nbsp;currentThread)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">&nbsp;(currentThread.isBlock)&nbsp;{</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;锁拥有者进行释放锁才有意义</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">&nbsp;(currentThread.next&nbsp;</span><span style="color: #000000; ">==</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">)&nbsp;{</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;检查是否有人排在自己后面</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">&nbsp;(UPDATER.compareAndSet(</span><span style="color: #0000FF; ">this</span><span style="color: #000000; ">,&nbsp;currentThread,&nbsp;</span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">))&nbsp;{</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;step&nbsp;4<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;compareAndSet返回true表示确实没有人排在自己后面</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #0000FF; ">else</span><span style="color: #000000; ">&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;突然有人排在自己后面了，可能还不知道是谁，下面是等待后续者<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;这里之所以要忙等是因为：step&nbsp;1执行完后，step&nbsp;2可能还没执行完</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">&nbsp;(currentThread.next&nbsp;</span><span style="color: #000000; ">==</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">)&nbsp;{&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;step&nbsp;5</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentThread.next.isBlock&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">false</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentThread.next&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;for&nbsp;GC</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</span></div><h3>CLH锁</h3><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;">CLH锁也是一种基于链表的可扩展、高性能、公平的自旋锁，申请线程只在本地变量上自旋，它不断轮询前驱的状态，如果发现前驱释放了锁就结束自旋。<br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">import</span><span style="color: #000000; ">&nbsp;java.util.concurrent.atomic.AtomicReferenceFieldUpdater;<br /><br /></span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">class</span><span style="color: #000000; ">&nbsp;CLHLock&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">static</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">class</span><span style="color: #000000; ">&nbsp;CLHNode&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">private</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">boolean</span><span style="color: #000000; ">&nbsp;isLocked&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">true</span><span style="color: #000000; ">;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;默认是在等待锁</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;@SuppressWarnings(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">unused</span><span style="color: #000000; ">"</span><span style="color: #000000; ">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">private</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">volatile</span><span style="color: #000000; ">&nbsp;CLHNode&nbsp;tail&nbsp;;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">private</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">static</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">final</span><span style="color: #000000; ">&nbsp;AtomicReferenceFieldUpdater</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">CLHLock,&nbsp;CLHNode</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">&nbsp;UPDATER&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;AtomicReferenceFieldUpdater<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.&nbsp;newUpdater(CLHLock.</span><span style="color: #0000FF; ">class</span><span style="color: #000000; ">,&nbsp;CLHNode&nbsp;.</span><span style="color: #0000FF; ">class</span><span style="color: #000000; ">&nbsp;,&nbsp;</span><span style="color: #000000; ">"</span><span style="color: #000000; ">tail</span><span style="color: #000000; ">"</span><span style="color: #000000; ">&nbsp;);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;lock(CLHNode&nbsp;currentThread)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CLHNode&nbsp;preNode&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;UPDATER.getAndSet(&nbsp;</span><span style="color: #0000FF; ">this</span><span style="color: #000000; ">,&nbsp;currentThread);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(preNode&nbsp;</span><span style="color: #000000; ">!=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">)&nbsp;{</span><span style="color: #008000; ">//</span><span style="color: #008000; ">已有线程占用了锁，进入自旋</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">(preNode.isLocked&nbsp;)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;unlock(CLHNode&nbsp;currentThread)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;如果队列里只有当前线程，则释放对当前线程的引用（for&nbsp;GC）。</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">&nbsp;(</span><span style="color: #000000; ">!</span><span style="color: #000000; ">UPDATER&nbsp;.compareAndSet(</span><span style="color: #0000FF; ">this</span><span style="color: #000000; ">,&nbsp;currentThread,&nbsp;</span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;还有后续线程</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentThread.&nbsp;isLocked&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">false</span><span style="color: #000000; ">&nbsp;;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;改变状态，让后续线程结束自旋</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</span></div><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;"><br /></p><h3>CLH锁 与 MCS锁 的比较</h3><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;">下图是CLH锁和MCS锁队列图示：<br /><img src="http://coderbee.net/wp-content/uploads/2013/11/CLH-MCS-SpinLock.png" alt="CLH-MCS-SpinLock" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; max-width: 100%; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; box-shadow: rgba(0, 0, 0, 0.2) 0px 1px 4px;" /></p><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;">差异：</p><ol style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; list-style-position: outside; list-style-image: initial; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;"><li style="margin: 0px 0px 0px 2.571428571rem; padding: 0px; border: 0px; vertical-align: baseline;">从代码实现来看，CLH比MCS要简单得多。</li><li style="margin: 0px 0px 0px 2.571428571rem; padding: 0px; border: 0px; vertical-align: baseline;">从自旋的条件来看，CLH是在本地变量上自旋，MCS是自旋在其他对象的属性。</li><li style="margin: 0px 0px 0px 2.571428571rem; padding: 0px; border: 0px; vertical-align: baseline;">从链表队列来看，CLH的队列是隐式的，CLHNode并不实际持有下一个节点；MCS的队列是物理存在的。</li><li style="margin: 0px 0px 0px 2.571428571rem; padding: 0px; border: 0px; vertical-align: baseline;">CLH锁释放时只需要改变自己的属性，MCS锁释放则需要改变后继节点的属性。</li></ol><p style="margin: 0px 0px 1.714285714rem; padding: 0px; border: 0px; vertical-align: baseline; line-height: 24px; color: #444444; font-family: 'Open Sans', Helvetica, Arial, sans-serif; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;">注意：这里实现的锁都是独占的，且不能重入的。</strong></p><img src ="http://www.blogjava.net/DLevin/aggbug/416102.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/DLevin/" target="_blank">DLevin</a> 2015-08-07 00:18 <a href="http://www.blogjava.net/DLevin/archive/2015/08/07/416102.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Servlet中web.xml配置文件(转)</title><link>http://www.blogjava.net/DLevin/archive/2014/05/18/413796.html</link><dc:creator>DLevin</dc:creator><author>DLevin</author><pubDate>Sat, 17 May 2014 16:43:00 GMT</pubDate><guid>http://www.blogjava.net/DLevin/archive/2014/05/18/413796.html</guid><wfw:comment>http://www.blogjava.net/DLevin/comments/413796.html</wfw:comment><comments>http://www.blogjava.net/DLevin/archive/2014/05/18/413796.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/DLevin/comments/commentRss/413796.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/DLevin/services/trackbacks/413796.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 转载自(虽然它本身也是转载自其他地方)：http://www.cnblogs.com/wy2325/archive/2013/03/25/2980683.html这篇文章转自JavaEye，以前配置web.xml时都不知道为什么这样，看了之后明白了很多。贴下来，共同分享！Web.xml常用元素&nbsp;&lt;web-app&gt;&nbsp;&lt;display-name&gt;&lt;/d...&nbsp;&nbsp;<a href='http://www.blogjava.net/DLevin/archive/2014/05/18/413796.html'>阅读全文</a><img src ="http://www.blogjava.net/DLevin/aggbug/413796.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/DLevin/" target="_blank">DLevin</a> 2014-05-18 00:43 <a href="http://www.blogjava.net/DLevin/archive/2014/05/18/413796.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【转】一个不错的eclipse反编译插件</title><link>http://www.blogjava.net/DLevin/archive/2012/11/02/390685.html</link><dc:creator>DLevin</dc:creator><author>DLevin</author><pubDate>Fri, 02 Nov 2012 07:05:00 GMT</pubDate><guid>http://www.blogjava.net/DLevin/archive/2012/11/02/390685.html</guid><wfw:comment>http://www.blogjava.net/DLevin/comments/390685.html</wfw:comment><comments>http://www.blogjava.net/DLevin/archive/2012/11/02/390685.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/DLevin/comments/commentRss/390685.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/DLevin/services/trackbacks/390685.html</trackback:ping><description><![CDATA[在CSDN论坛上看到的一个不错的eclipse反编译插件，感觉看起来不错的样子，因而记下，原网址是：<a href="http://topic.csdn.net/u/20121030/14/CDE52930-BAF2-4F88-B751-3797A7EB3C44.html">http://topic.csdn.net/u/20121030/14/CDE52930-BAF2-4F88-B751-3797A7EB3C44.html</a><br /><br />闲暇之余，写了一个Eclipse下的Java反编译插件：Eclipse Class Decompiler，整合了目前最好的2个Java反编译工具Jad和JD-Core，并且和Eclipse Class Viewer无缝集成，能够很方便的使用本插件查看类库源码，以及采用本插件进行Debug调试。<br /><br /><strong sizset="44" sizcache="0">Eclipse Class Decompiler插件更新站点： <a title="http://feeling.sourceforge.net/update" href="http://feeling.sourceforge.net/update" target="_blank">http://feeling.sourceforge.net/update</a></strong><br /><br />直接使用Eclipse进行更新，支持Eclipse 3.x, 4.x，不依赖任何其他插件，直接勾选更新插件即可。<br /><br /><img alt="" src="http://www.blogjava.net/images/blogjava_net/cnfree/install.png" /><br /><br /><br />下图为Eclipse Class Decompiler的首选项页面，可以选择缺省的反编译器工具，并进行反编译器的基本设置。缺省的反编译工具为JD-Core，JD-Core更为先进一些，支持泛型、Enum、注解等JDK1.5以后才有的新语法。<br /><br /><img alt="" src="http://www.blogjava.net/images/blogjava_net/cnfree/preferences.png" /><br /><br />首选项配置选项：<br />1.重用缓存代码：只会反编译一次，以后每次打开该类文件，都显示的是缓存的反编译代码。<br />2.忽略已存在的源代码：若未选中，则查看Class文件是否已绑定了Java源代码，如果已绑定，则显示Java源代码，如果未绑定，则反编译Class文件。若选中此项，则忽略已绑定的Java源代码，显示反编译结果。<br />3.显示反编译器报告：显示反编译器反编译后生成的数据报告及异常信息。<br />4.使用Eclipse代码格式化工具：使用Eclipse格式化工具对反编译结果重新格式化排版，反编译整个Jar包时，此操作会消耗一些时间。<br />5.使用Eclipse成员排序：使用Eclipse成员排序对反编译结果重新格式化排版，反编译整个Jar包时，此操作会消耗大量时间。<br />6.以注释方式输出原始行号信息：如果Class文件包含原始行号信息，则会将行号信息以注释的方式打印到反编译结果中。<br />7.根据行号对齐源代码以便于调试：若选中该项，插件会采用AST工具分析反编译结果，并根据行号信息调整代码顺序，以便于Debug过程中的单步跟踪调试。<br />8.设置类反编译查看器作为缺省的类文件编辑器：默认为选中，将忽略Eclipse自带的Class Viewer，每次Eclipse启动后，默认使用本插件提供的类查看器打开Class文件。<br /><br /><br />插件提供了系统菜单，工具栏，当打开了插件提供的类反编译查看器后，会激活菜单和工具栏选项，可以方便的进行首选项配置，切换反编译工具重新反编译，以及导出反编译结果。<br /><br /><img alt="" src="http://www.blogjava.net/images/blogjava_net/cnfree/MenuBar.png" /><br /><img alt="" src="http://www.blogjava.net/images/blogjava_net/cnfree/ToolBar.png" /><br /><br /><br />类反编译查看器右键菜单包含了Eclipse自带类查看器右键菜单的全部选项，并增加了一个&#8220;导出反编译源代码&#8221;菜单项。<br /><br /><img alt="" src="http://www.blogjava.net/images/blogjava_net/cnfree/export.png" /><br /><br />打开项目路径下的Class文件，如果设置类反编译查看器为缺省的查看器，直接双击Class文件即可，如果没有设置为缺省查看器，可以使用右键菜单进行查看。<br /><br /><img alt="" src="http://www.blogjava.net/images/blogjava_net/cnfree/open.png" /><br /><br /><br />Eclipse Class Decompiler插件也提供了反编译整个Jar文件或者Java包的反编译。该操作支持Package Explorer对包显示布局的操作，如果是平铺模式布局，则导出的源代码不包含子包，如果是层级模式布局，则导出选中的包及其所有的子包。<br /><br /><img alt="" src="http://www.blogjava.net/images/blogjava_net/cnfree/ExportPackage.png" /><br /><br /><br />Debug调试：可以在首选项选中对齐行号进行单步跟踪调试，和普通的包含源代码时的调试操作完全一致，同样的也可以设置断点进行跟踪。<br /><br /><img alt="" src="http://www.blogjava.net/images/blogjava_net/cnfree/Debug.png" /><br /><img src ="http://www.blogjava.net/DLevin/aggbug/390685.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/DLevin/" target="_blank">DLevin</a> 2012-11-02 15:05 <a href="http://www.blogjava.net/DLevin/archive/2012/11/02/390685.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【转】Log4j/common log和各种服务器集成的问题</title><link>http://www.blogjava.net/DLevin/archive/2012/11/02/390639.html</link><dc:creator>DLevin</dc:creator><author>DLevin</author><pubDate>Thu, 01 Nov 2012 18:08:00 GMT</pubDate><guid>http://www.blogjava.net/DLevin/archive/2012/11/02/390639.html</guid><wfw:comment>http://www.blogjava.net/DLevin/comments/390639.html</wfw:comment><comments>http://www.blogjava.net/DLevin/archive/2012/11/02/390639.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/DLevin/comments/commentRss/390639.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/DLevin/services/trackbacks/390639.html</trackback:ping><description><![CDATA[转自：<a href="http://xinyanfei.blog.sohu.com/72361504.html">http://xinyanfei.blog.sohu.com/72361504.html</a><br />我从转到Java开发后，一直在开发Application Server，所以基本没有和大型的Web Server打过交道，所以关于common logging在这些server上部署时遇到的问题也只能是从理论上去解释。感觉这篇文章介绍的不错，所以转载过来。<br /><br /><span class="Apple-style-span" style="color: #62613b; font-family: Verdana, Arial, Helvetica, 宋体, sans-serif; line-height: 25px; ">&nbsp; 目前的很多商业和非商业的服务器中间件都默认集成了common-log甚至是log4j.因此当我门把我们的应用发布在上面的时候,都会遇到关于log方面的问题.<br style="line-height: 25px; " />&nbsp; 1.webshpere下面集成log4j.<br style="line-height: 25px; " />&nbsp; "WebSphere的类装入器方式有两种方式：PARENT_FIRST和PARENT_LAST。默认值是PARENT_FIRST，这种方式在载入当前classpath的类之前先载入其上一级classloader能够装入的类。这是标准的JVM classloader的默认策略。如果采用PARENT_LAST，则过程正好相反，即先载入当前classpath的类，再载入其上一级classloader能够装入的类，这样可以用当前classpath中更新的类覆盖其上一级classloader的相同类。受类装入器方式影响的classloader包括application classloader、WAR classloader以及共享类库的classloader。"<br style="line-height: 25px; " />&nbsp;因为websphere在共享类库的classloader中有一套common logging,但是确没有合适配置文件.如果我们把配置正确的log4j.properties文件放在共享类库下,我们会发现log4j可以运行.但还有另外一个很通用的方式--改变webshpere的类库加载顺序.我们让他先加载我们web应用所需的类库.即我们把web应用的加栽方式改为PARENT_LAST.<br style="line-height: 25px; " />&nbsp; 哎,尽管我小心的提防,今天还是中招了,在我的配置里,log4j的配置文件只能读取一次,不能一个应用一个配置文件.为了让它加载自己的配置,可以自己写(或者用spring的)servlet/listener去手动加载这个配置文件.<br style="line-height: 25px; " />&nbsp;2.jboss下面的集成log4j<br style="line-height: 25px; " />&nbsp; 大家可能都曾在为jboss下面配置log4j郁闷过.jboss比webshpere走的还远.无论你的项目是否使用了log4j,jboss在自己启动的时候就已经运行他了.也就是说在jboss加载自己共享类库的时候,已经读取了自己log4j.xml文件配置.这个文件在conf中可以找到.如果你需要为你的应用单独配置一个catagory,你需要直接在这里配置．<br style="line-height: 25px; " />&nbsp;&nbsp;&nbsp;在webloader装载应用的时候,如果应用中有log4j的包,似乎总出现appender已被占用的问题.笔者把log4j的包连带应用中的log4j配置文件一并移去,世界清净了.<br style="line-height: 25px; " />关于为了让应用自带的log4j配置文件生效,有人建议修改<br style="line-height: 25px; " />&nbsp;&lt;attribute name="Java2ClassLoadingCompliance"&gt;false&lt;/attribute&gt;<br style="line-height: 25px; " />和<br style="line-height: 25px; " />&nbsp;&lt;attribute name="UseJBossWebLoader"&gt;false&lt;/attribute&gt;<br style="line-height: 25px; " />这两个属性．<br style="line-height: 25px; " />　３．sunone下面集成log4j<br style="line-height: 25px; " />&nbsp;&nbsp;&nbsp; 距离上次用SunOne服务器已经好长时间了,似乎sunOne的log有些类似jboss,也是一个服务器的log集中管理.由于使用的不是很多,暂且在这里站个位子.<br style="line-height: 25px; " />随手贴点关于log的信息:<br style="line-height: 25px; " /><a href="http://wiki.apache.org/jakarta-commons/Logging/FrequentlyAskedQuestions" style="line-height: 21px; color: #62613b; font: normal normal normal 12px/normal Verdana, Arial, Helvetica, 宋体, sans-serif; text-decoration: underline; ">http://wiki.apache.org/jakarta-commons/Logging/FrequentlyAskedQuestions</a><br style="line-height: 25px; " /><a href="http://www-128.ibm.com/developerworks/cn/websphere/library/techarticles/0408_baigang/part3.html" style="line-height: 21px; color: #62613b; font: normal normal normal 12px/normal Verdana, Arial, Helvetica, 宋体, sans-serif; text-decoration: underline; ">http://www-128.ibm.com/developerworks/cn/websphere/library/techarticles/0408_baigang/part3.html</a></span><br /><img src ="http://www.blogjava.net/DLevin/aggbug/390639.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/DLevin/" target="_blank">DLevin</a> 2012-11-02 02:08 <a href="http://www.blogjava.net/DLevin/archive/2012/11/02/390639.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【转】为什么很多程序员都选择跳槽？</title><link>http://www.blogjava.net/DLevin/archive/2012/09/04/386964.html</link><dc:creator>DLevin</dc:creator><author>DLevin</author><pubDate>Tue, 04 Sep 2012 07:10:00 GMT</pubDate><guid>http://www.blogjava.net/DLevin/archive/2012/09/04/386964.html</guid><wfw:comment>http://www.blogjava.net/DLevin/comments/386964.html</wfw:comment><comments>http://www.blogjava.net/DLevin/archive/2012/09/04/386964.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/DLevin/comments/commentRss/386964.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/DLevin/services/trackbacks/386964.html</trackback:ping><description><![CDATA[<p sizset="27" sizcache="1">转自：龙铭洪博客 <a href="http://blog.csdn.net/long892230">http://blog.csdn.net/long892230</a><br /><br />今天看到一个帖子：&#8220;<a href="http://blog.csdn.net/">程序员</a>内部晋升越来越困难，但是外部来的大P越来越多，所以很多人都选择跳槽&#8221;，之后我从三个方面简要的进行了回答：&#8220;外面来的总是有包装的，内部的都是肉身PK，此一输；外面来的总是小股人马，内部的一批批的，升谁都伤感情，此二输；外面来的通常都是大佬推荐的，没有特别重大机会，人不会来，内部的就不解释了，成果都被大佬吸收，难有机会，此三输&#8221;。之后讨论不断，我也余兴未了，继续写来。</p>
<p>这个世界上有一类人特别苦逼，苦逼到什么程度呢？他们省吃俭用攒钱买房，结果房价越来越贵；公司外部竞争激烈，他们工作异常繁忙，披星戴月，日复一日；技术更新行业罕见，他们要随时调整心情，随时学习知识；他们长期和机器为伍，大多比较呆傻，比较单纯；还有很多不一一例举，这一类人就是程序员。</p>
<p>而就是这么一类程序员过着这么苦逼的生活，在公司内部却难以获得公平的晋升机会，外来的和尚总是在不断打破平衡，甚至是刚毕业的新和尚拿得都比老和尚多，这是全行业都罕见的奇观，IT人有幸经历了。</p>
<p>某创业公司，某个程序员要离职，老板甚至不问问他直接领导的意见，就同意了，没有挽留，之后大骂不忠诚，这个人拿3k，拿了2年，他走了以后，老板用5k雇了个新面孔，但就是不愿意给这个老人晋升，不愿意给加到哪怕是4k。</p>
<p>某上市公司，游戏部门突然从外部空降了一个领导，原因是原大佬被挖走以后，剩下的人升谁都有意见，难以服众，不从外部请人来镇不住局面，这个人一来，大家是团结了，团结起来和这个人斗，但最后还是和解了。</p>
<p>某国际大公司，某人伪造简历，包装的如花似玉，获得高职，工作主要有下属完成，他只需要汇众汇报即可，越混路越宽，直到某天事发，依然是高官。</p>
<p sizset="28" sizcache="1">某IT企业，某清华同学离职时语重心长的对我说，XX（可以理解为网游，搜索，电商任意一种）是00-02年毕业的这些人清华人的机会，我们就是比某人强十倍也没有机会，也得从下面做起，搜索的天时不属于我，此人去了某金融分析软件公司，目前是高管，同期留在某<a href="http://http//blog.csdn.net">IT</a>企业的其他同学依然过着苦逼的生活。</p>
<h3>举了这么多例子，我想说得是为什么不给你晋升这个问题，或者晋升很难，为什么？</h3>
<p><strong>1）大佬的问题</strong></p>
<p>你晋升困难，最大的主观原因在你自己，最大的客观原因在你的直接上司。付责任人的说，目前很多企业的领导是不合格的，他们大多80后，没有为他人着想的思想基础，一味的考虑自己，不顾下属，曾经我对某人说，你说你是合格的领导，你说出你下属每个员工租房在哪里，每月多少房租，我就同意你是合格的领导，结果他羞愧不言。你晋升不了，很大程度上是你的领导没有帮你，连你每月房租多少都不知道，你指望他帮助你提高技术水平，帮助你晋升？</p>
<p><strong>2）大佬的大佬的问题</strong></p>
<p>你大佬的大佬，level很高，他需要引入新鲜血液，他知道这个队伍缺什么，这个是他思考的问题，他需要找牛的人来补这个缺口，于是一个光鲜照人的牛人进来了（虽然两年后也会泯为众人）给队伍带来了新鲜的血液，但你的大佬升不上去，你大佬边上的位置被这个人占了，你的位置在哪？</p>
<p><strong>3）公司的问题</strong></p>
<p>各大企业给员工的再教育和培训都是不尽相同的，但大多口号是一致的，在工作中锻炼成长，这句话是最扯淡的，国外很多大公司是有很完善的培训和再教育计划的，会给员工一个充电的机会，并且给其一个完善的培训后，以便于让他在新升职的岗位上能够很好的胜任。在国内大公司都在找牛人，就是不愿意自己培养，原因是什么，不解释，你懂得。</p>
<p><strong>4）你的兄弟</strong></p>
<p>很多时候让你升不了职恰恰是因为和你一起战斗的兄弟，他们工作也很不错，你升职了，他们怎么办？这也是一个平衡的问题，你很努力，为什么你没有带动你的兄弟一起努力，你上去了，需要你这帮兄弟的支持，他们会支持你吗？曾有一个说了一句话，我觉得很值得回味，&#8220;当大家都认为你该升职了，就是你升职的时候了&#8221;，细细品味，很有道理。</p>
<p><strong>5）你自己的问题</strong></p>
<p>最后你升不了职是你自己的问题，每天工作很忙，没时间充电，每天工作压力很大，来不及学习，每天这个那个，一年下来碌碌无为。你提高了自己的效率了嘛？你周围有朋友再帮你吗？你知道你要学什么嘛？你知道什么样的工作才能超出领导的期望?，你超出领导期望后却没有升职和领导沟通过吗？我曾在某企业，我周围的几乎所有人加薪升职都是和领导沟通后才获得的。指望主动给你加薪升职，不如指望自己的沟通。</p>
<p><strong>6）还是你自己的问题</strong></p>
<p>你选择的这个行业是不是对的，公司是不是对的，就好像我说的这个清华的同学这个例子。如果你能耐大可以选大公司，PK到一票牛人上去，如果你能耐不大，去成熟大公司，还心理期盼高薪升职就不现实了，不如去一个有前途的中小公司，开创自己的事业。</p>
<h3>从企业角度出发，如何创建一个合理公平的晋升机制呢？</h3>
<p>1）第一流大佬才会招第一流的人，第二流大佬只会招第三流的人，因此公司一把手必须是第一流的，价值观才能靠谱，制度才靠谱，没熟读历史，不理解中国文化的，建议不要做公司一把手。</p>
<p>2）晋升的制度必须公平，面向每一个人，每一个层次，这往往很难做到，做前端的和做后台的不好比，但做前端的可以和做前端的比。必须要有公开公平的比拼，已获得升职机会。例如某公司做一个高维矩阵分解的难题，大家机会均等，性能最快，效果最好，胜出者升职，带领团队。</p>
<p>3）鼓励公司职员交流，传播和帮助他人的文化，一个人如果乐于助人，帮助他人提高技术水平，这个人升职升上来，大家都会顶，反之，你保守，不帮助他人，水平再牛，升职上来也没人支持。</p>
<p>4）可以给职员一些挑战的机会，提供更多的资源，比如某公司的闪电计划，超越了谷歌搜索效果，就是一个很好的例子，要敢于给一些勇于挑战的职员更多的资源，在严酷的战斗中考验，并提供充分弹药。</p>
<p>5）给予内训机会，邀请业界牛人讲座，送职员去美帝考察开会乃至工作等等。培训机会是发达国家企业的一种非常好的激励措施，一个岗位5个人培训，最好的上岗，这是一个很公平的机会，培训机构足够独立。&nbsp;&nbsp;&nbsp;<br />方法有很多，只要这第一流的大佬，心中有着这帮打生打死的兄弟，办法总是有的，不要总是考虑自己的业绩，考虑自己的乌纱帽，做到这一点很难很难，但制度不是只有这位大佬可以制定，任何职员都应该积极投身到制度建立的过程中，要敢于提出自己的观点，毕竟公司是大家的公司。</p>
<p sizset="29" sizcache="1">我就写这么多，我是一个十年一线<strong sizset="29" sizcache="1"><a href="http://blog.csdn.net/">程序员</a></strong>的身份写这篇博客的，我努力做到客观，但我相信我更多代表的是劳方立场。</p><img src ="http://www.blogjava.net/DLevin/aggbug/386964.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/DLevin/" target="_blank">DLevin</a> 2012-09-04 15:10 <a href="http://www.blogjava.net/DLevin/archive/2012/09/04/386964.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>20世纪《福布斯》二十本最具影响力的商业书籍</title><link>http://www.blogjava.net/DLevin/archive/2012/07/12/368317.html</link><dc:creator>DLevin</dc:creator><author>DLevin</author><pubDate>Thu, 12 Jul 2012 03:12:00 GMT</pubDate><guid>http://www.blogjava.net/DLevin/archive/2012/07/12/368317.html</guid><wfw:comment>http://www.blogjava.net/DLevin/comments/368317.html</wfw:comment><comments>http://www.blogjava.net/DLevin/archive/2012/07/12/368317.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/DLevin/comments/commentRss/368317.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/DLevin/services/trackbacks/368317.html</trackback:ping><description><![CDATA[<div class="floatright"><span><a class="image" title="" href="http://wiki.mbalib.com/wiki/Image:Most_Influential_Business_Books.jpg"><div><div><br /><a href="http://docs.huihoo.com/java/jmx/jmx_base.html">http://docs.huihoo.com/java/jmx/jmx_base.html</a></div>http://blog.csdn.net/honno/article/details/1798476</div><img alt="" src="http://wiki.mbalib.com/w/images/3/37/Most_Influential_Business_Books.jpg" width="185" longdesc="/wiki/Image:Most_Influential_Business_Books.jpg" height="97" /></a></span></div>
<p>　　《<a title="福布斯" href="http://wiki.mbalib.com/wiki/%E7%A6%8F%E5%B8%83%E6%96%AF">福布斯</a>》杂志评出了上个世纪末最具影响力的二十本商业书籍。上世纪70年代末，美国经济陷入衰退的阵痛期，来自阿拉伯世界的石油威胁及来自日本的经济压力使美国人的日子很不好过，商业书籍也因此被尘封一时。但在接下来的80和90年代，美国经济保持了二十年的持续增长，一大批优秀的<a title="CEO" href="http://wiki.mbalib.com/wiki/CEO">CEO</a>如<a title="比尔&#183;盖茨" href="http://wiki.mbalib.com/wiki/%E6%AF%94%E5%B0%94%C2%B7%E7%9B%96%E8%8C%A8">比尔&#183;盖茨</a>、<a title="李&#183;艾科卡" href="http://wiki.mbalib.com/wiki/%E6%9D%8E%C2%B7%E8%89%BE%E7%A7%91%E5%8D%A1">李&#183;艾科卡</a>、<a title="唐纳德&#183;特朗普" href="http://wiki.mbalib.com/wiki/%E5%94%90%E7%BA%B3%E5%BE%B7%C2%B7%E7%89%B9%E6%9C%97%E6%99%AE">唐纳德&#183;特朗普</a>，出现在人们的视野中。商业书籍的出版和发行也因此空前活跃，本次评出的二十本书按类别分为管理类、叙事类、投资类及传记类。它们分别是： </p>
<p>　　<strong>汤姆&#183;彼得斯错了吗？</strong> </p>
<p>　　管理类书籍在整个排行榜上所占的比重最大，其中<a title="汤姆&#183;彼得斯" href="http://wiki.mbalib.com/wiki/%E6%B1%A4%E5%A7%86%C2%B7%E5%BD%BC%E5%BE%97%E6%96%AF">汤姆&#183;彼得斯</a>(<a title="Thomas Peters" href="http://wiki.mbalib.com/wiki/Thomas_Peters">Thomas Peters</a>)的<a title="《追求卓越》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E8%BF%BD%E6%B1%82%E5%8D%93%E8%B6%8A%E3%80%8B">《追求卓越》</a>高居榜首。这本书出版于1982年，最开始源自著名的咨询公司<a title="麦肯锡" href="http://wiki.mbalib.com/wiki/%E9%BA%A6%E8%82%AF%E9%94%A1">麦肯锡</a>的一个内部项目。当时的美国商业界正倍受日本公司咄咄逼人的扩张姿态的困扰，日本公司普遍采用的严格的<a title="制度化管理" href="http://wiki.mbalib.com/wiki/%E5%88%B6%E5%BA%A6%E5%8C%96%E7%AE%A1%E7%90%86">制度化管理</a>让这个战败国的经济迅速崛起。面对强烈个人主义精神的员工，美国公司领导成了被长期讥笑的低能者。<a title="汤姆&#183;彼得斯" href="http://wiki.mbalib.com/wiki/%E6%B1%A4%E5%A7%86%C2%B7%E5%BD%BC%E5%BE%97%E6%96%AF">汤姆&#183;彼得斯</a>与<a title="罗伯特&#183;沃特曼" href="http://wiki.mbalib.com/wiki/%E7%BD%97%E4%BC%AF%E7%89%B9%C2%B7%E6%B2%83%E7%89%B9%E6%9B%BC">罗伯特&#183;沃特曼</a>的《追求卓越》成了美国商业的拯救者。这本书为管理设定了一个积极的目标，而非强调面临的难题。彼得斯提出的杰出企业的 8个特性几乎为未来20年的商业管理奠定了格局： </p>
<p>　　1.偏好行动而不是沉思 </p>
<p>　　2.在产品和服务上接近顾客的需求 </p>
<p>　　3.鼓励自治和放松，而不是紧密监督 </p>
<p>　　4.对雇员的态度是鼓励其生产力，避免&#8220;我们&#8221;和&#8220;他们&#8221;这种对立情绪 </p>
<p>　　5.以一种被称为&#8220;<a title="走动式管理" href="http://wiki.mbalib.com/wiki/%E8%B5%B0%E5%8A%A8%E5%BC%8F%E7%AE%A1%E7%90%86">走动式管理</a>&#8221;保持与大家的紧密接触 </p>
<p>　　6.&#8220;专注于自身&#8221;以保持商业优势，因此避免了无关的风险 </p>
<p>　　7.组织结构简洁，人员精干 </p>
<p>　　8.对目标同时保持松紧有度的特性，但却不窒息创新的控制系统。 </p>
<p>　　今日的企业领袖没有人不承认深受汤姆&#183;彼得斯原则的影响。《追求卓越》成为第一本销量超过百万的商业书籍，这本书甚至促成了商业书籍出版业的成熟。汤姆&#183;彼得斯也成了一位标志性的明星人物。 </p>
<p>　　今日的汤姆&#183;彼得斯已经失去了最初的光彩，人们甚至开始遗忘他了。在《追求卓越》出版20周年之际，汤姆&#183;彼得斯亲自撰文，讲述他写这本书的初衷和过程，他的观点对在哪里，错在哪里，他承认当时自己说了一些谎话。对于试图为商界确定未来日程的精英来说，《追求卓越》背后的故事提供了一系列不可多得的教训。此书引导的潮流向我们展示了20年来商业世界急剧变化的生动图景。 </p>
<p>　　&#8220;我们忘了贴一个警告标签。注意！没有永恒的东西。任何东西吃得太多都会有毒。请记住：商业中所有事情都是悖论。为达到追求，必须持之以恒。而当你持之以恒之时，你就容易受到攻击。你看，这就是悖论。面对它吧！&#8221;这是此书出版20年之后汤姆&#183;彼得斯的再一次表白，&#8220;卓越只是一种过于静态的观念，而世界实在变化太快了。&#8221; </p>
<p>　　<strong>好公司能否变成卓越公司</strong> </p>
<p>　　排名第二的是<a title="吉姆&#183;柯林斯" href="http://wiki.mbalib.com/wiki/%E5%90%89%E5%A7%86%C2%B7%E6%9F%AF%E6%9E%97%E6%96%AF">吉姆&#183;柯林斯</a>(<a title="James C. Collins" href="http://wiki.mbalib.com/wiki/James_C._Collins">James C. Collins</a>)和<a title="杰里&#183;波拉斯" href="http://wiki.mbalib.com/wiki/%E6%9D%B0%E9%87%8C%C2%B7%E6%B3%A2%E6%8B%89%E6%96%AF">杰里&#183;波拉斯</a>(<a title="Jerry I. Porras" href="http://wiki.mbalib.com/wiki/Jerry_I._Porras">Jerry I. Porras</a>)的著作<a title="《基业长青》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E5%9F%BA%E4%B8%9A%E9%95%BF%E9%9D%92%E3%80%8B">《基业长青》</a>。在书中作者对那些有见识有远见的公司进行了介绍。许多人认为一间公司的持续成长依赖于几位优秀的<a title="CEO" href="http://wiki.mbalib.com/wiki/CEO">CEO</a>的持续运作，但本书的作者却告诉人们，对一个企业而言，一群聪明人在维持现状的基础上敢于进行新尝试比拥有一个有魅力的领袖更重要，而拥有一个核心的理念并为之奋斗则是企业的关键所在。 </p>
<p>　　<a title="吉姆&#183;柯林斯" href="http://wiki.mbalib.com/wiki/%E5%90%89%E5%A7%86%C2%B7%E6%9F%AF%E6%9E%97%E6%96%AF">吉姆&#183;柯林斯</a>的另一本书<a title="《从优秀到卓越》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E4%BB%8E%E4%BC%98%E7%A7%80%E5%88%B0%E5%8D%93%E8%B6%8A%E3%80%8B">《从优秀到卓越》</a>同样榜上有名。 </p>
<p>　　<a title="《基业长青》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E5%9F%BA%E4%B8%9A%E9%95%BF%E9%9D%92%E3%80%8B">《基业长青》</a>这本书研究了18个基业常青公司的成功经验。这些公司包括<a title="沃尔玛" href="http://wiki.mbalib.com/wiki/%E6%B2%83%E5%B0%94%E7%8E%9B">沃尔玛</a>、<a title="惠普" href="http://wiki.mbalib.com/wiki/%E6%83%A0%E6%99%AE">惠普</a>、<a title="宝洁" href="http://wiki.mbalib.com/wiki/%E5%AE%9D%E6%B4%81">宝洁</a>、<a title="3M" href="http://wiki.mbalib.com/wiki/3M">3M</a>和<a title="索尼" href="http://wiki.mbalib.com/wiki/%E7%B4%A2%E5%B0%BC">索尼</a>等行业领袖，本书研究的是事件，是人性。作者从人的角度让我们看到了公司的成长和巩固。作者分析的是公司、组织以及人在组织中的作用。作者从公司的角度分析了使得企业长远发展的优势，以此分析企业取得这些优势并长期发展的原因。企业在发展过程中必须不断自我改革、自我反省来达到这些优势，使其成为公司特性，从而保证长久发展。 </p>
<p>　　为了进一步探寻那些优秀的公司走向不同发展道路的因素，2001年，<a title="吉姆&#183;柯林斯" href="http://wiki.mbalib.com/wiki/%E5%90%89%E5%A7%86%C2%B7%E6%9F%AF%E6%9E%97%E6%96%AF">吉姆&#183;柯林斯</a>又出版了一本《从优秀到卓越》，这本书可说是《基业长青》的姊妹篇。还在出版《基业长青》之时，柯林斯就提出，好的公司能否变成卓越的公司？如果能够，他们如何才能实现呢？之后，他们对1400多个公司进行了研究，最后得出了结论，这是可以达到的。那些由优秀的公司变为伟大公司的佼佼者并不一定都拥有最新的技术、最擅长管理的CEO，他们最有力的武器是他们的公司文化，一种激励每个人都按照他们想要的方式去工作的文化。综合这两本书，我们已经知道如何由一个优秀的公司发展成为一个卓越的公司，这些公司都是经历了时间考验的。那些正在变革的路口，不知要去向何方的公司或许能在科林斯的书中找到一些提示和方向。 </p>
<p>　　<strong>《公司再造》潮流的起落</strong> </p>
<p>　　《追求卓越》和《基业长青》集中介绍企业如何取得超人的成就，而排名第三的<a title="《公司再造》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E5%85%AC%E5%8F%B8%E5%86%8D%E9%80%A0%E3%80%8B">《公司再造》</a>(<a title="Reengineering the Corporation：A Manifesto for Business Revolution" href="http://wiki.mbalib.com/wiki/Reengineering_the_Corporation%EF%BC%9AA_Manifesto_for_Business_Revolution">Reengineering the Corporation：A Manifesto for Business Revolution</a>)则聚焦在企业如何进行自我改造。书中研究了<a title="福特" href="http://wiki.mbalib.com/wiki/%E7%A6%8F%E7%89%B9">福特</a>、<a title="IBM" href="http://wiki.mbalib.com/wiki/IBM">IBM</a>及<a title="贝尔公司" href="http://wiki.mbalib.com/wiki/%E8%B4%9D%E5%B0%94%E5%85%AC%E5%8F%B8">贝尔公司</a>的案例并介绍了相关的成功经验。 </p>
<p>　　1993年，<a title="迈克尔&#183;汉默" href="http://wiki.mbalib.com/wiki/%E8%BF%88%E5%85%8B%E5%B0%94%C2%B7%E6%B1%89%E9%BB%98">迈克尔&#183;汉默</a>(<a title="Michael Hammer" href="http://wiki.mbalib.com/wiki/Michael_Hammer">Michael Hammer</a>)与<a title="James Champy" href="http://wiki.mbalib.com/wiki/James_Champy">James Champy</a>出版了<a title="《企业再造》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E4%BC%81%E4%B8%9A%E5%86%8D%E9%80%A0%E3%80%8B">《企业再造》</a>一书，系统阐述了<a title="BPR" href="http://wiki.mbalib.com/wiki/BPR">BPR</a>(Business Process Reengineering)的思想，提出再造企业的首要任务是BPR，只有建设好BPR，才能使企业彻底摆脱困境。至此，BPR作为一种新的管理思想，像一股风潮席卷了整个美国和其他工业化国家。 </p>
<p>　　BPR就是将企业的业务过程描绘成一个<a title="价值链" href="http://wiki.mbalib.com/wiki/%E4%BB%B7%E5%80%BC%E9%93%BE">价值链</a>(Value Chain)，竞争不是发生在企业与企业之间，而是发生在企业各自的价值链之间。只有对价值链的各个环节(<a title="业务流程" href="http://wiki.mbalib.com/wiki/%E4%B8%9A%E5%8A%A1%E6%B5%81%E7%A8%8B">业务流程</a>)实行有效管理的企业，才有可能真正获得市场上的<a title="竞争优势" href="http://wiki.mbalib.com/wiki/%E7%AB%9E%E4%BA%89%E4%BC%98%E5%8A%BF">竞争优势</a>，也惟其如此，BPR才被捧为&#8220;恢复美国竞争力的惟一途径&#8221;。 </p>
<p>　　BPR的产生，并不仅仅是一本书那么简单，隐藏在BPR背后的是深刻的技术、经济以及管理变革背景。 </p>
<p>　　资本主义进入70年代以来，全球经济环境发生了巨大的变化，供大于求的现状促成了<a title="卖方市场" href="http://wiki.mbalib.com/wiki/%E5%8D%96%E6%96%B9%E5%B8%82%E5%9C%BA">卖方市场</a>转向<a title="买方市场" href="http://wiki.mbalib.com/wiki/%E4%B9%B0%E6%96%B9%E5%B8%82%E5%9C%BA">买方市场</a>。进入80年代，以美国为代表的资本主义发达国家经济陷入增长缓慢和<a title="通货膨胀" href="http://wiki.mbalib.com/wiki/%E9%80%9A%E8%B4%A7%E8%86%A8%E8%83%80">通货膨胀</a>的尴尬困境，企业陷入了成本增加、效益降低的局面，<a title="产品竞争力" href="http://wiki.mbalib.com/wiki/%E4%BA%A7%E5%93%81%E7%AB%9E%E4%BA%89%E5%8A%9B">产品竞争力</a>与亚太国家相比陷入不断下降的局面。美国的企业迫切期望改变这种现状，走出低谷，从70到90年代陆续出现的新型管理手段以及管理方法为BPR奠定了腾空而出的基础条件。 </p>
<p>　　90年代初应运而生的BPR正好迎合了企业的这种思想和需要。BPR完全满足了欧美企业急于走出<a title="经济萧条" href="http://wiki.mbalib.com/wiki/%E7%BB%8F%E6%B5%8E%E8%90%A7%E6%9D%A1">经济萧条</a>、寻求持续增长和适应新的商业规则的心理需求，也满足了学术界在迷茫中寻求管理思想革新的迫切心理。 </p>
<p>　　BPR从1990年概念的诞生，短短3年的时间，到1993年达到顶峰，在美国几乎形成一股风潮，同时还波及到日本、德国等其他工业化国家。1990年到1995年是BPR在欧美最为鼎盛的时期。90年代末期，经济的持续稳定导致BPR成为美国企业率先遗弃的对象。 </p>
<p>　　另一本受欢迎的书籍<a title="《高效人群的七种习惯》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E9%AB%98%E6%95%88%E4%BA%BA%E7%BE%A4%E7%9A%84%E4%B8%83%E7%A7%8D%E4%B9%A0%E6%83%AF%E3%80%8B">《高效人群的七种习惯》</a>着重介绍个人管理。这本书虽然已经出版了十多年之久，并已达到了上千万的销量，但时至今日仍然是图书市场上的宠儿。有趣的是，虽然数以千万计的人购买了它，但人们的平均工作效率似乎并没有比十年前有所提高。本书作者<a title="史蒂芬&#183;柯维" href="http://wiki.mbalib.com/wiki/%E5%8F%B2%E8%92%82%E8%8A%AC%C2%B7%E6%9F%AF%E7%BB%B4">史蒂芬&#183;柯维</a>却因此名声大振，他的私人公司<a class="new" title="富兰克林&#183;柯维" href="http://wiki.mbalib.com/w/index.php?title=%E5%AF%8C%E5%85%B0%E5%85%8B%E6%9E%97%C2%B7%E6%9F%AF%E7%BB%B4&amp;action=edit">富兰克林&#183;柯维</a>(Franklin Covey)在2001年的销售额高达5亿2000万美元。 </p>
<p>　　还有一位值得一提的作者当数<a title="彼得&#183;德鲁克" href="http://wiki.mbalib.com/wiki/%E5%BD%BC%E5%BE%97%C2%B7%E5%BE%B7%E9%B2%81%E5%85%8B">彼得&#183;德鲁克</a>。他所写的管理学著作早在<a title="汤姆&#183;彼得斯" href="http://wiki.mbalib.com/wiki/%E6%B1%A4%E5%A7%86%C2%B7%E5%BD%BC%E5%BE%97%E6%96%AF">汤姆&#183;彼得斯</a>的《追求卓越》之前。在本次评选中，他的<a class="new" title="《德鲁克的核心思想》" href="http://wiki.mbalib.com/w/index.php?title=%E3%80%8A%E5%BE%B7%E9%B2%81%E5%85%8B%E7%9A%84%E6%A0%B8%E5%BF%83%E6%80%9D%E6%83%B3%E3%80%8B&amp;action=edit">《德鲁克的核心思想》</a>被公认为是最有影响力的商业书籍之一。 </p>
<p>　　<strong><a title="杰克&#183;韦尔奇" href="http://wiki.mbalib.com/wiki/%E6%9D%B0%E5%85%8B%C2%B7%E9%9F%A6%E5%B0%94%E5%A5%87">杰克&#183;韦尔奇</a>：再老也会让你惊讶</strong> </p>
<p>　　<a title="CEO" href="http://wiki.mbalib.com/wiki/CEO">CEO</a>的传记历来都是出版商追捧的对象，然而最早的CEO传记&#8212;&#8212;1985年由Bantam出版公司推出的<a class="new" title="《艾科卡》" href="http://wiki.mbalib.com/w/index.php?title=%E3%80%8A%E8%89%BE%E7%A7%91%E5%8D%A1%E3%80%8B&amp;action=edit">《艾科卡》</a>(《Lacocca》) 在此次评选中却榜上无名。同样名噪一时的传记体书籍<a class="new" title="《交易的艺术》" href="http://wiki.mbalib.com/w/index.php?title=%E3%80%8A%E4%BA%A4%E6%98%93%E7%9A%84%E8%89%BA%E6%9C%AF%E3%80%8B&amp;action=edit">《交易的艺术》</a>(1988年，Random House公司出版)也与排行榜无缘。 </p>
<p>　　由华纳公司出版的<a title="《杰克&#183;韦尔奇自传》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E6%9D%B0%E5%85%8B%C2%B7%E9%9F%A6%E5%B0%94%E5%A5%87%E8%87%AA%E4%BC%A0%E3%80%8B">《杰克&#183;韦尔奇自传》</a>受到评选人士的一致认可。近来，CEO<a title="杰克&#183;韦尔奇" href="http://wiki.mbalib.com/wiki/%E6%9D%B0%E5%85%8B%C2%B7%E9%9F%A6%E5%B0%94%E5%A5%87">杰克&#183;韦尔奇</a>虽然在婚姻问题上颇受争议，但他仍然被公认为代表了一个时代的最杰出的CEO人选。同他合著该书的《<a title="商业周刊" href="http://wiki.mbalib.com/wiki/%E5%95%86%E4%B8%9A%E5%91%A8%E5%88%8A">商业周刊</a>》的<a class="new" title="约翰&#183;伯恩" href="http://wiki.mbalib.com/w/index.php?title=%E7%BA%A6%E7%BF%B0%C2%B7%E4%BC%AF%E6%81%A9&amp;action=edit">约翰&#183;伯恩</a>的著作<a class="new" title="《价值链》" href="http://wiki.mbalib.com/w/index.php?title=%E3%80%8A%E4%BB%B7%E5%80%BC%E9%93%BE%E3%80%8B&amp;action=edit">《价值链》</a>也在评选中颇受关注。 </p>
<p>　　杰克&#183;韦尔奇在担任<a title="通用公司" href="http://wiki.mbalib.com/wiki/%E9%80%9A%E7%94%A8%E5%85%AC%E5%8F%B8">通用公司</a>CEO的20年中，带领这个工业巨人积累了超过4500亿美元的市场资本，并使自己成为全世界最受人尊敬的企业领导。他提倡并促进了现代企业的<a title="电子商务" href="http://wiki.mbalib.com/wiki/%E7%94%B5%E5%AD%90%E5%95%86%E5%8A%A1">电子商务</a>、<a title="六西格玛" href="http://wiki.mbalib.com/wiki/%E5%85%AD%E8%A5%BF%E6%A0%BC%E7%8E%9B">六西格玛</a>体系&#8212;&#8212;即在100万次生产或服务作业中的瑕疵率不超过6次、质量体系和全球化进程。同时，他建立了一套独特的<a title="企业哲学" href="http://wiki.mbalib.com/wiki/%E4%BC%81%E4%B8%9A%E5%93%B2%E5%AD%A6">企业哲学</a>和管理方法。其理念是打破一切界限地吸收有用的思想；把人当成企业的核心；建立自由的投入产出模式，以抵御<a title="官僚主义" href="http://wiki.mbalib.com/wiki/%E5%AE%98%E5%83%9A%E4%B8%BB%E4%B9%89">官僚主义</a>的产生。 </p>
<p>　　杰克带领通用公司进入了&#8220;中子杰克&#8221;时代，他在每一个通用企业中推行&#8220;整顿、出售和关闭&#8221;的策略，从而使通用公司逐步裁减了10万雇员；他通过购并<a title="RCA公司" href="http://wiki.mbalib.com/wiki/RCA%E5%85%AC%E5%8F%B8">RCA公司</a>为通用未来的赢利奠定了基础&#8230;&#8230;当然，也有失误的时候，但是杰克能够用一种坦诚的心态去面对失误。在&#8220;自大的自己&#8221;这一章中，他承认收购<a class="new" title="Kidder Peabody公司" href="http://wiki.mbalib.com/w/index.php?title=Kidder_Peabody%E5%85%AC%E5%8F%B8&amp;action=edit">Kidder Peabody公司</a>是自己最大的失败，因为该公司和通用公司的文化背道而驰。对于在职业生涯最后一年煞费苦心地收购<a title="霍尼韦尔" href="http://wiki.mbalib.com/wiki/%E9%9C%8D%E5%B0%BC%E9%9F%A6%E5%B0%94">霍尼韦尔</a>并遭遇失败的全过程，本书也做了详尽的交代。这位善于自嘲的经理人说这让他明白了一个道理：再老也会有让你惊讶的事情。的确，如果韦尔奇撰写自传续集的话，他会向读者解释他的婚姻危机和关于巨额退休金的满城风雨吗？ </p>
<p>　　在传记类作品中，另一本著名的传记<a title="《摩根财团》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E6%91%A9%E6%A0%B9%E8%B4%A2%E5%9B%A2%E3%80%8B">《摩根财团》</a>于1990年问世，书中描述了<a title="J.P.摩根" href="http://wiki.mbalib.com/wiki/J.P.%E6%91%A9%E6%A0%B9">J.P.摩根</a>的帝国如何从诞生到陨落的过程，该书获得了1990 年全美最佳图书奖，并在商界人士之中广泛流传。<a title="微软" href="http://wiki.mbalib.com/wiki/%E5%BE%AE%E8%BD%AF">微软</a>的总裁<a title="比尔&#183;盖茨" href="http://wiki.mbalib.com/wiki/%E6%AF%94%E5%B0%94%C2%B7%E7%9B%96%E8%8C%A8">比尔&#183;盖茨</a>是这个时代最富有的人，他的两本描述信息世界的书<a class="new" title="《未来之路》" href="http://wiki.mbalib.com/w/index.php?title=%E3%80%8A%E6%9C%AA%E6%9D%A5%E4%B9%8B%E8%B7%AF%E3%80%8B&amp;action=edit">《未来之路》</a>和<a class="new" title="《未来时速》" href="http://wiki.mbalib.com/w/index.php?title=%E3%80%8A%E6%9C%AA%E6%9D%A5%E6%97%B6%E9%80%9F%E3%80%8B&amp;action=edit">《未来时速》</a>虽然引人注目，但却没有荣登本次排行榜。 </p>
<div style="float: right; margin-left: 5px" class="editsection">[<a title="编辑段落: 排名榜单" href="http://wiki.mbalib.com/w/index.php?title=20%E4%B8%96%E7%BA%AA%E3%80%8A%E7%A6%8F%E5%B8%83%E6%96%AF%E3%80%8B%E4%BA%8C%E5%8D%81%E6%9C%AC%E6%9C%80%E5%85%B7%E5%BD%B1%E5%93%8D%E5%8A%9B%E7%9A%84%E5%95%86%E4%B8%9A%E4%B9%A6%E7%B1%8D&amp;action=edit&amp;section=2">编辑</a>]</div><a name=".E6.8E.92.E5.90.8D.E6.A6.9C.E5.8D.95"></a>
<h2>排名榜单</h2>
<table class="wikitable">
<tbody>
<tr>
<th>排名(Rank)</th>
<th>书名(Title)</th>
<th>作者(Author)</th>
<th>出版商(Publisher)</th>
<th>年份(Year)</th>
<th>类型(Genre) </th></tr>
<tr>
<td>1</td>
<td><a title="《追求卓越》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E8%BF%BD%E6%B1%82%E5%8D%93%E8%B6%8A%E3%80%8B">《追求卓越》</a>(<a title="In Search of Excellence: Lessons from America's Best-Run Companies" href="http://wiki.mbalib.com/wiki/In_Search_of_Excellence:_Lessons_from_America%27s_Best-Run_Companies">In Search of Excellence: Lessons from America's Best-Run Companies</a>)</td>
<td><a title="汤姆&#183;彼得斯" href="http://wiki.mbalib.com/wiki/%E6%B1%A4%E5%A7%86%C2%B7%E5%BD%BC%E5%BE%97%E6%96%AF">汤姆&#183;彼得斯</a>(<a title="Thomas Peters" href="http://wiki.mbalib.com/wiki/Thomas_Peters">Thomas Peters</a>), <a title="罗伯特&#183;沃特曼" href="http://wiki.mbalib.com/wiki/%E7%BD%97%E4%BC%AF%E7%89%B9%C2%B7%E6%B2%83%E7%89%B9%E6%9B%BC">罗伯特&#183;沃特曼</a>(<a title="Robert H. Waterman" href="http://wiki.mbalib.com/wiki/Robert_H._Waterman">Robert H. Waterman</a>)</td>
<td>哈珀与罗出版公司(Harper &amp; Row)</td>
<td>1982</td>
<td>管理著作(Management) </td></tr>
<tr>
<td>2</td>
<td><a title="《基业长青》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E5%9F%BA%E4%B8%9A%E9%95%BF%E9%9D%92%E3%80%8B">《基业长青》</a>(<a title="Built to Last: Successful Habits of Visionary Companies" href="http://wiki.mbalib.com/wiki/Built_to_Last:_Successful_Habits_of_Visionary_Companies">Built to Last: Successful Habits of Visionary Companies</a>)</td>
<td><a title="吉姆&#183;柯林斯" href="http://wiki.mbalib.com/wiki/%E5%90%89%E5%A7%86%C2%B7%E6%9F%AF%E6%9E%97%E6%96%AF">吉姆&#183;柯林斯</a>(<a title="James C. Collins" href="http://wiki.mbalib.com/wiki/James_C._Collins">James C. Collins</a>), <a title="杰里&#183;波拉斯" href="http://wiki.mbalib.com/wiki/%E6%9D%B0%E9%87%8C%C2%B7%E6%B3%A2%E6%8B%89%E6%96%AF">杰里&#183;波拉斯</a>(<a title="Jerry I. Porras" href="http://wiki.mbalib.com/wiki/Jerry_I._Porras">Jerry I. Porras</a>)</td>
<td>哈珀&#183;柯林斯一般图书出版集团(HarperCollins)</td>
<td>1994</td>
<td>管理著作(Management) </td></tr>
<tr>
<td>3</td>
<td><a title="《公司再造》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E5%85%AC%E5%8F%B8%E5%86%8D%E9%80%A0%E3%80%8B">《公司再造》</a>(<a title="Reengineering the Corporation：A Manifesto for Business Revolution" href="http://wiki.mbalib.com/wiki/Reengineering_the_Corporation%EF%BC%9AA_Manifesto_for_Business_Revolution">Reengineering the Corporation：A Manifesto for Business Revolution</a>)</td>
<td><a title="迈克尔&#183;哈默" href="http://wiki.mbalib.com/wiki/%E8%BF%88%E5%85%8B%E5%B0%94%C2%B7%E5%93%88%E9%BB%98">迈克尔&#183;哈默</a>(<a title="Michael Hammer" href="http://wiki.mbalib.com/wiki/Michael_Hammer">Michael Hammer</a>), <a title="詹姆斯&#183;钱皮" href="http://wiki.mbalib.com/wiki/%E8%A9%B9%E5%A7%86%E6%96%AF%C2%B7%E9%92%B1%E7%9A%AE">詹姆斯&#183;钱皮</a>(<a title="James A. Champy" href="http://wiki.mbalib.com/wiki/James_A._Champy">James A. Champy</a>)</td>
<td>哈珀&#183;柯林斯一般图书出版集团(HarperCollins)</td>
<td>1993</td>
<td>管理著作(Management) </td></tr>
<tr>
<td>4</td>
<td><a title="《门口的野蛮人》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E9%97%A8%E5%8F%A3%E7%9A%84%E9%87%8E%E8%9B%AE%E4%BA%BA%E3%80%8B">《门口的野蛮人》</a>(<a title="Barbarians at the Gate: The Fall of RJR Nabisco" href="http://wiki.mbalib.com/wiki/Barbarians_at_the_Gate:_The_Fall_of_RJR_Nabisco">Barbarians at the Gate: The Fall of RJR Nabisco</a>)</td>
<td><a class="new" title="布赖恩&#183;伯勒" href="http://wiki.mbalib.com/w/index.php?title=%E5%B8%83%E8%B5%96%E6%81%A9%C2%B7%E4%BC%AF%E5%8B%92&amp;action=edit">布赖恩&#183;伯勒</a>(<a class="new" title="Bryan Burrough" href="http://wiki.mbalib.com/w/index.php?title=Bryan_Burrough&amp;action=edit">Bryan Burrough</a>), <a class="new" title="约翰&#183;希利亚尔" href="http://wiki.mbalib.com/w/index.php?title=%E7%BA%A6%E7%BF%B0%C2%B7%E5%B8%8C%E5%88%A9%E4%BA%9A%E5%B0%94&amp;action=edit">约翰&#183;希利亚尔</a>(<a class="new" title="John Helyar" href="http://wiki.mbalib.com/w/index.php?title=John_Helyar&amp;action=edit">John Helyar</a>)</td>
<td>哈珀&#183;柯林斯一般图书出版集团（HarperCollins）</td>
<td>1990</td>
<td>小说(Narrative) </td></tr>
<tr>
<td>5</td>
<td><a title="《竞争优势》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E7%AB%9E%E4%BA%89%E4%BC%98%E5%8A%BF%E3%80%8B">《竞争优势》</a>(<a title="Competitive Advantage: Creating and Sustaining Superior Performance" href="http://wiki.mbalib.com/wiki/Competitive_Advantage:_Creating_and_Sustaining_Superior_Performance">Competitive Advantage: Creating and Sustaining Superior Performance</a>)</td>
<td><a title="迈克尔&#183;波特" href="http://wiki.mbalib.com/wiki/%E8%BF%88%E5%85%8B%E5%B0%94%C2%B7%E6%B3%A2%E7%89%B9">迈克尔&#183;波特</a>(<a title="Michael E. Porter" href="http://wiki.mbalib.com/wiki/Michael_E._Porter">Michael E. Porter</a>)</td>
<td>自由出版社(Free Press)</td>
<td>1998</td>
<td>管理著作(Management) </td></tr>
<tr>
<td>6</td>
<td><a title="《引爆流行:小事如何产生大变化》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E5%BC%95%E7%88%86%E6%B5%81%E8%A1%8C:%E5%B0%8F%E4%BA%8B%E5%A6%82%E4%BD%95%E4%BA%A7%E7%94%9F%E5%A4%A7%E5%8F%98%E5%8C%96%E3%80%8B">《引爆流行:小事如何产生大变化》</a>(<a title="The Tipping Point: How Little Things Can Make a Big Difference" href="http://wiki.mbalib.com/wiki/The_Tipping_Point:_How_Little_Things_Can_Make_a_Big_Difference">The Tipping Point: How Little Things Can Make a Big Difference</a>)</td>
<td><a title="马尔科姆&#183;格莱德威尔" href="http://wiki.mbalib.com/wiki/%E9%A9%AC%E5%B0%94%E7%A7%91%E5%A7%86%C2%B7%E6%A0%BC%E8%8E%B1%E5%BE%B7%E5%A8%81%E5%B0%94">马尔科姆&#183;格莱德威尔</a>(<a title="Malcolm Gladwell" href="http://wiki.mbalib.com/wiki/Malcolm_Gladwell">Malcolm Gladwell</a>)</td>
<td>利特尔&amp;布朗出版社(Little Brown)</td>
<td>2000</td>
<td>小说(Narrative) </td></tr>
<tr>
<td>7</td>
<td><a title="《跨越鸿沟》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E8%B7%A8%E8%B6%8A%E9%B8%BF%E6%B2%9F%E3%80%8B">《跨越鸿沟》</a>(<a title="Crossing the Chasm: Marketing and Selling Technology Products to Mainstream Customers" href="http://wiki.mbalib.com/wiki/Crossing_the_Chasm:_Marketing_and_Selling_Technology_Products_to_Mainstream_Customers">Crossing the Chasm: Marketing and Selling Technology Products to Mainstream Customers</a>)</td>
<td><a title="杰弗瑞&#183;摩尔" href="http://wiki.mbalib.com/wiki/%E6%9D%B0%E5%BC%97%E7%91%9E%C2%B7%E6%91%A9%E5%B0%94">杰弗瑞&#183;摩尔</a>(<a title="Geoffrey A. Moore" href="http://wiki.mbalib.com/wiki/Geoffrey_A._Moore">Geoffrey A. Moore</a>)</td>
<td>哈珀&#183;柯林斯一般图书出版集团商业分社(HarperBusiness)</td>
<td>1999</td>
<td>管理著作(Management) </td></tr>
<tr>
<td>8</td>
<td><a title="《摩根财团》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E6%91%A9%E6%A0%B9%E8%B4%A2%E5%9B%A2%E3%80%8B">《摩根财团》</a>(<a title="The House of Morgan: An American Banking Dynasty and the Rise of Modern Finance" href="http://wiki.mbalib.com/wiki/The_House_of_Morgan:_An_American_Banking_Dynasty_and_the_Rise_of_Modern_Finance">The House of Morgan: An American Banking Dynasty and the Rise of Modern Finance</a>)</td>
<td><a class="new" title="罗恩&#183;彻诺" href="http://wiki.mbalib.com/w/index.php?title=%E7%BD%97%E6%81%A9%C2%B7%E5%BD%BB%E8%AF%BA&amp;action=edit">罗恩&#183;彻诺</a>(<a class="new" title="Ron Chernow" href="http://wiki.mbalib.com/w/index.php?title=Ron_Chernow&amp;action=edit">Ron Chernow</a>)</td>
<td>亚特兰大月刊出版社Atlantic Monthly Press</td>
<td>1990</td>
<td>人物传记(Biography) </td></tr>
<tr>
<td>9</td>
<td><a title="《六西格玛之路》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E5%85%AD%E8%A5%BF%E6%A0%BC%E7%8E%9B%E4%B9%8B%E8%B7%AF%E3%80%8B">《六西格玛之路》</a>(<a title="The Six Sigma Way" href="http://wiki.mbalib.com/wiki/The_Six_Sigma_Way">The Six Sigma Way</a>)</td>
<td><a class="new" title="彼得&#183;潘蒂" href="http://wiki.mbalib.com/w/index.php?title=%E5%BD%BC%E5%BE%97%C2%B7%E6%BD%98%E8%92%82&amp;action=edit">彼得&#183;潘蒂</a>(<a class="new" title="Peter S. Pande et al" href="http://wiki.mbalib.com/w/index.php?title=Peter_S._Pande_et_al&amp;action=edit">Peter S. Pande et al</a>), <a class="new" title="罗伯特&#183;纽曼" href="http://wiki.mbalib.com/w/index.php?title=%E7%BD%97%E4%BC%AF%E7%89%B9%C2%B7%E7%BA%BD%E6%9B%BC&amp;action=edit">罗伯特&#183;纽曼</a><a class="new" title="Robert P. Neuman" href="http://wiki.mbalib.com/w/index.php?title=Robert_P._Neuman&amp;action=edit">Robert P. Neuman</a>, <a class="new" title="罗兰&#183;卡法那夫" href="http://wiki.mbalib.com/w/index.php?title=%E7%BD%97%E5%85%B0%C2%B7%E5%8D%A1%E6%B3%95%E9%82%A3%E5%A4%AB&amp;action=edit">罗兰&#183;卡法那夫</a>(<a class="new" title="Roland R. Cavanagh" href="http://wiki.mbalib.com/w/index.php?title=Roland_R._Cavanagh&amp;action=edit">Roland R. Cavanagh</a>)</td>
<td><a title="麦格劳&#183;希尔公司" href="http://wiki.mbalib.com/wiki/%E9%BA%A6%E6%A0%BC%E5%8A%B3%C2%B7%E5%B8%8C%E5%B0%94%E5%85%AC%E5%8F%B8">麦格劳&#183;希尔公司</a>(McGraw-Hill)</td>
<td>2000</td>
<td>管理著作(Management) </td></tr>
<tr>
<td>10</td>
<td><a title="《高效人士的七个习惯》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E9%AB%98%E6%95%88%E4%BA%BA%E5%A3%AB%E7%9A%84%E4%B8%83%E4%B8%AA%E4%B9%A0%E6%83%AF%E3%80%8B">《高效人士的七个习惯》</a>(<a title="Seven Habits of Highly Effective People: Powerful Lessons in Personal Change" href="http://wiki.mbalib.com/wiki/Seven_Habits_of_Highly_Effective_People:_Powerful_Lessons_in_Personal_Change">Seven Habits of Highly Effective People: Powerful Lessons in Personal Change</a>)</td>
<td><a title="斯蒂芬&#183;科维" href="http://wiki.mbalib.com/wiki/%E6%96%AF%E8%92%82%E8%8A%AC%C2%B7%E7%A7%91%E7%BB%B4">斯蒂芬&#183;科维</a>(<a title="Stephen R. Covey" href="http://wiki.mbalib.com/wiki/Stephen_R._Covey">Stephen R. Covey</a>)</td>
<td>西蒙和舒斯特公司(Simon &amp; Schuster)</td>
<td>1990</td>
<td>管理著作(Management) </td></tr>
<tr>
<td>11</td>
<td><a title="《谎言家的纸牌》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E8%B0%8E%E8%A8%80%E5%AE%B6%E7%9A%84%E7%BA%B8%E7%89%8C%E3%80%8B">《谎言家的纸牌》</a>(<a title="Liar's Poker" href="http://wiki.mbalib.com/wiki/Liar%27s_Poker">Liar's Poker</a>)</td>
<td><a class="new" title="迈克尔&#183;刘易斯" href="http://wiki.mbalib.com/w/index.php?title=%E8%BF%88%E5%85%8B%E5%B0%94%C2%B7%E5%88%98%E6%98%93%E6%96%AF&amp;action=edit">迈克尔&#183;刘易斯</a>(<a class="new" title="Michael Lewis" href="http://wiki.mbalib.com/w/index.php?title=Michael_Lewis&amp;action=edit">Michael Lewis</a>)</td>
<td>W.W．诺顿出版社(W.W. Norton)</td>
<td>1989</td>
<td>小说(Narrative) </td></tr>
<tr>
<td>12</td>
<td><a title="《创新者的窘境》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E5%88%9B%E6%96%B0%E8%80%85%E7%9A%84%E7%AA%98%E5%A2%83%E3%80%8B">《创新者的窘境》</a>(<a title="The Innovator's Dilemma: When New Technologies Cause Great Firms to Fail" href="http://wiki.mbalib.com/wiki/The_Innovator%27s_Dilemma:_When_New_Technologies_Cause_Great_Firms_to_Fail">The Innovator's Dilemma: When New Technologies Cause Great Firms to Fail</a>)</td>
<td><a title="克莱顿&#183;克里斯坦森" href="http://wiki.mbalib.com/wiki/%E5%85%8B%E8%8E%B1%E9%A1%BF%C2%B7%E5%85%8B%E9%87%8C%E6%96%AF%E5%9D%A6%E6%A3%AE">克莱顿&#183;克里斯坦森</a>(<a title="Clayton M. Christensen" href="http://wiki.mbalib.com/wiki/Clayton_M._Christensen">Clayton M. Christensen</a>)</td>
<td>哈佛商学院出版社(Harvard Business School Press)</td>
<td>1997</td>
<td>管理著作(Management) </td></tr>
<tr>
<td>13</td>
<td><a title="《日本公司》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E6%97%A5%E6%9C%AC%E5%85%AC%E5%8F%B8%E3%80%8B">《日本公司》</a>(<a title="Japan Inc." href="http://wiki.mbalib.com/wiki/Japan_Inc.">Japan Inc.</a>)</td>
<td><a class="new" title="石森章太郎" href="http://wiki.mbalib.com/w/index.php?title=%E7%9F%B3%E6%A3%AE%E7%AB%A0%E5%A4%AA%E9%83%8E&amp;action=edit">石森章太郎</a>(<a class="new" title="Shotaro Ishinomori" href="http://wiki.mbalib.com/w/index.php?title=Shotaro_Ishinomori&amp;action=edit">Shotaro Ishinomori</a>)</td>
<td>加利福尼亚大学出版社(University of California Press)</td>
<td>1988</td>
<td>管理著作(Management) </td></tr>
<tr>
<td>14</td>
<td><a title="《贼巢》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E8%B4%BC%E5%B7%A2%E3%80%8B">《贼巢》</a>(<a title="Den of Thieves" href="http://wiki.mbalib.com/wiki/Den_of_Thieves">Den of Thieves</a>)</td>
<td><a class="new" title="詹姆斯&#183;B&#183;斯图尔特" href="http://wiki.mbalib.com/w/index.php?title=%E8%A9%B9%E5%A7%86%E6%96%AF%C2%B7B%C2%B7%E6%96%AF%E5%9B%BE%E5%B0%94%E7%89%B9&amp;action=edit">詹姆斯&#183;B&#183;斯图尔特</a>(<a class="new" title="James B. Stewart" href="http://wiki.mbalib.com/w/index.php?title=James_B._Stewart&amp;action=edit">James B. Stewart</a>)</td>
<td>西蒙和舒斯特公司(Simon &amp; Schuster)</td>
<td>1991</td>
<td>小说(Narrative) </td></tr>
<tr>
<td>15</td>
<td><a title="《德鲁克精华》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E5%BE%B7%E9%B2%81%E5%85%8B%E7%B2%BE%E5%8D%8E%E3%80%8B">《德鲁克精华》</a><a title="The Essential Drucker" href="http://wiki.mbalib.com/wiki/The_Essential_Drucker">The Essential Drucker</a></td>
<td><a title="彼得&#183;德鲁克" href="http://wiki.mbalib.com/wiki/%E5%BD%BC%E5%BE%97%C2%B7%E5%BE%B7%E9%B2%81%E5%85%8B">彼得&#183;德鲁克</a>(<a title="Peter F. Drucker" href="http://wiki.mbalib.com/wiki/Peter_F._Drucker">Peter F. Drucker</a>)</td>
<td>哈珀&#183;柯林斯一般图书出版集团商业分社(HarperBusiness)</td>
<td>2001</td>
<td>管理著作(Management) </td></tr>
<tr>
<td>16</td>
<td><a title="《为未来竞争》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E4%B8%BA%E6%9C%AA%E6%9D%A5%E7%AB%9E%E4%BA%89%E3%80%8B">《为未来竞争》</a>(<a title="Competing for the Future" href="http://wiki.mbalib.com/wiki/Competing_for_the_Future">Competing for the Future</a>)</td>
<td><a title="加里&#183;哈默尔" href="http://wiki.mbalib.com/wiki/%E5%8A%A0%E9%87%8C%C2%B7%E5%93%88%E9%BB%98%E5%B0%94">加里&#183;哈默尔</a>(<a title="Gary Hamel" href="http://wiki.mbalib.com/wiki/Gary_Hamel">Gary Hamel</a>), <a title="普拉哈拉德" href="http://wiki.mbalib.com/wiki/%E6%99%AE%E6%8B%89%E5%93%88%E6%8B%89%E5%BE%B7">普拉哈拉德</a>(<a title="C. K. Prahalad" href="http://wiki.mbalib.com/wiki/C._K._Prahalad">C. K. Prahalad</a>)</td>
<td>哈佛商学院出版社(Harvard Business School Press)</td>
<td>1994</td>
<td>管理著作(Management) </td></tr>
<tr>
<td>17</td>
<td><a title="《巴菲特之道：世界上最伟大的投资家的投资战略》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E5%B7%B4%E8%8F%B2%E7%89%B9%E4%B9%8B%E9%81%93%EF%BC%9A%E4%B8%96%E7%95%8C%E4%B8%8A%E6%9C%80%E4%BC%9F%E5%A4%A7%E7%9A%84%E6%8A%95%E8%B5%84%E5%AE%B6%E7%9A%84%E6%8A%95%E8%B5%84%E6%88%98%E7%95%A5%E3%80%8B">《巴菲特之道：世界上最伟大的投资家的投资战略》</a>(<a title="The Buffett Way: Investment Strategies of the World's Greatest Investor" href="http://wiki.mbalib.com/wiki/The_Buffett_Way:_Investment_Strategies_of_the_World%27s_Greatest_Investor">The Buffett Way: Investment Strategies of the World's Greatest Investor</a>)</td>
<td><a class="new" title="罗伯特&#183;哈格斯特龙" href="http://wiki.mbalib.com/w/index.php?title=%E7%BD%97%E4%BC%AF%E7%89%B9%C2%B7%E5%93%88%E6%A0%BC%E6%96%AF%E7%89%B9%E9%BE%99&amp;action=edit">罗伯特&#183;哈格斯特龙</a>(<a class="new" title="Robert G. Hagstrom" href="http://wiki.mbalib.com/w/index.php?title=Robert_G._Hagstrom&amp;action=edit">Robert G. Hagstrom</a>)</td>
<td>约翰&#183;威利父子公司(John Wiley &amp; Sons)</td>
<td>1991</td>
<td>投资(Investing) </td></tr>
<tr>
<td>18</td>
<td><a title="《杰克&#183;韦尔奇自传》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E6%9D%B0%E5%85%8B%C2%B7%E9%9F%A6%E5%B0%94%E5%A5%87%E8%87%AA%E4%BC%A0%E3%80%8B">《杰克&#183;韦尔奇自传》</a>(<a title="Jack: Straight from the Gut" href="http://wiki.mbalib.com/wiki/Jack:_Straight_from_the_Gut">Jack: Straight from the Gut</a>)</td>
<td><a title="杰克&#183;韦尔奇" href="http://wiki.mbalib.com/wiki/%E6%9D%B0%E5%85%8B%C2%B7%E9%9F%A6%E5%B0%94%E5%A5%87">杰克&#183;韦尔奇</a>(<a title="Jack Welch" href="http://wiki.mbalib.com/wiki/Jack_Welch">Jack Welch</a>), <a class="new" title="约翰&#183;拜恩斯" href="http://wiki.mbalib.com/w/index.php?title=%E7%BA%A6%E7%BF%B0%C2%B7%E6%8B%9C%E6%81%A9%E6%96%AF&amp;action=edit">约翰&#183;拜恩斯</a>(<a class="new" title="John A. Byrne" href="http://wiki.mbalib.com/w/index.php?title=John_A._Byrne&amp;action=edit">John A. Byrne</a>)</td>
<td>时代华纳贸易出版公司(Warner)</td>
<td>2001</td>
<td>传记(Biography) </td></tr>
<tr>
<td>19</td>
<td><a title="《从优秀到卓越》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E4%BB%8E%E4%BC%98%E7%A7%80%E5%88%B0%E5%8D%93%E8%B6%8A%E3%80%8B">《从优秀到卓越》</a>(<a title="Good to Great: Why Some Companies Make the Leap... and Others Don't" href="http://wiki.mbalib.com/wiki/Good_to_Great:_Why_Some_Companies_Make_the_Leap..._and_Others_Don%27t">Good to Great: Why Some Companies Make the Leap... and Others Don't</a>)</td>
<td><a title="吉姆&#183;柯林斯" href="http://wiki.mbalib.com/wiki/%E5%90%89%E5%A7%86%C2%B7%E6%9F%AF%E6%9E%97%E6%96%AF">吉姆&#183;柯林斯</a>(<a title="James Collins" href="http://wiki.mbalib.com/wiki/James_Collins">James Collins</a>)</td>
<td>哈珀&#183;柯林斯一般图书出版集团(HarperCollins)</td>
<td>2001</td>
<td>管理著作(Management) </td></tr>
<tr>
<td>20</td>
<td><a title="《新新事物--硅谷文化》" href="http://wiki.mbalib.com/wiki/%E3%80%8A%E6%96%B0%E6%96%B0%E4%BA%8B%E7%89%A9--%E7%A1%85%E8%B0%B7%E6%96%87%E5%8C%96%E3%80%8B">《新新事物--硅谷文化》</a>(<a title="The New New Thing: A Silicon Valley Story" href="http://wiki.mbalib.com/wiki/The_New_New_Thing:_A_Silicon_Valley_Story">The New New Thing: A Silicon Valley Story</a>)</td>
<td><a class="new" title="迈克尔&#183;刘易斯" href="http://wiki.mbalib.com/w/index.php?title=%E8%BF%88%E5%85%8B%E5%B0%94%C2%B7%E5%88%98%E6%98%93%E6%96%AF&amp;action=edit">迈克尔&#183;刘易斯</a>(<a class="new" title="Michael Lewis" href="http://wiki.mbalib.com/w/index.php?title=Michael_Lewis&amp;action=edit">Michael Lewis</a>)</td>
<td>W.W．诺顿出版社(W.W. Norton)</td>
<td>2000</td>
<td>小说(Narrative) </td></tr></tbody></table> <img src ="http://www.blogjava.net/DLevin/aggbug/368317.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/DLevin/" target="_blank">DLevin</a> 2012-07-12 11:12 <a href="http://www.blogjava.net/DLevin/archive/2012/07/12/368317.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【转】Windows Shell扩展编程傻瓜手册大全：上下文菜单扩展</title><link>http://www.blogjava.net/DLevin/archive/2012/07/12/373911.html</link><dc:creator>DLevin</dc:creator><author>DLevin</author><pubDate>Thu, 12 Jul 2012 03:11:00 GMT</pubDate><guid>http://www.blogjava.net/DLevin/archive/2012/07/12/373911.html</guid><wfw:comment>http://www.blogjava.net/DLevin/comments/373911.html</wfw:comment><comments>http://www.blogjava.net/DLevin/archive/2012/07/12/373911.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/DLevin/comments/commentRss/373911.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/DLevin/services/trackbacks/373911.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 引用自：http://blog.163.com/yesaidu@126/blog/static/51819307200861853827582/ Part I: A step-by-step tutorial on writing shell extensions第一节：Windows shell扩展初步：上下文菜单扩展&nbsp;作者：Michael Dunn译者：yesai...&nbsp;&nbsp;<a href='http://www.blogjava.net/DLevin/archive/2012/07/12/373911.html'>阅读全文</a><img src ="http://www.blogjava.net/DLevin/aggbug/373911.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/DLevin/" target="_blank">DLevin</a> 2012-07-12 11:11 <a href="http://www.blogjava.net/DLevin/archive/2012/07/12/373911.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]关于面试、简历之类的某人聊天的观点</title><link>http://www.blogjava.net/DLevin/archive/2012/07/02/381984.html</link><dc:creator>DLevin</dc:creator><author>DLevin</author><pubDate>Mon, 02 Jul 2012 05:51:00 GMT</pubDate><guid>http://www.blogjava.net/DLevin/archive/2012/07/02/381984.html</guid><wfw:comment>http://www.blogjava.net/DLevin/comments/381984.html</wfw:comment><comments>http://www.blogjava.net/DLevin/archive/2012/07/02/381984.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/DLevin/comments/commentRss/381984.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/DLevin/services/trackbacks/381984.html</trackback:ping><description><![CDATA[<p><font style="background-color: #cce8cf">在CSDN上看到的，感觉说的蛮好的，转过来收藏一下，原文地址：<a href="http://topic.csdn.net/u/20120629/17/d130a88b-54fc-4402-8d12-b573872d96b3.html">http://topic.csdn.net/u/20120629/17/d130a88b-54fc-4402-8d12-b573872d96b3.html</a><br />2012/2/2 15:13:23&nbsp; <br />有一个原则&nbsp; <br />2012/2/2 15:13:29&nbsp; <br />如果我投简历给你&nbsp; <br />2012/2/2 15:13:36&nbsp; <br />就代表我接受挑选&nbsp; <br />2012/2/2 15:13:44&nbsp; <br />那么你怎么样，我都遵守&nbsp; <br />2012/2/2 15:13:49&nbsp; <br />如果是你打电话给我&nbsp; <br />2012/2/2 15:13:57&nbsp; <br />那是你邀请我&nbsp; <br />2012/2/2 15:14:04&nbsp; <br />那么你必须足够尊重我&nbsp; <br />2012/2/2 15:14:10&nbsp; <br />不然不玩&nbsp; <br />2012/2/2 15:14:22&nbsp; <br />这是不同的，我申请的，我尊重你，&nbsp; <br />2012/2/2 15:14:29&nbsp; <br />你邀请的，你尊重我&nbsp; <br />2012/2/2 15:14:44&nbsp; <br />你尊重都做不到，还说啥&nbsp; <br />2012/2/2 15:15:04&nbsp; <br />你把人邀请来了，又要人做笔试，你疯了吧&nbsp; <br />2012/2/2 15:15:25&nbsp; <br />我从来面试不带笔&nbsp; <br />2012/2/2 15:15:33&nbsp; <br />也不带别的&nbsp; <br />2012/2/2 15:15:35&nbsp; <br />别的&nbsp; <br />2012/2/2 15:15:40&nbsp; <br />没多少&nbsp; <br />2012/2/2 15:15:42&nbsp; <br />不说了&nbsp; <br />2012/2/2 15:16:34&nbsp; <br />企业和面试者是平等关系&nbsp; <br />2012/2/2 15:16:49&nbsp; <br />我每次招人，我都会问人家，你接受笔试不&nbsp; <br />2012/2/2 15:16:57&nbsp; <br />你不接受，我不勉强&nbsp; <br />2012/2/2 15:17:19&nbsp; <br />但是你真的技术无法判断，又不愿意笔试，我就只能说买卖不成仁义在&nbsp; <br />2012/2/2 15:17:47&nbsp; <br />我不认为拒绝笔试是不尊重我，但有的时候需要笔试，我会先说明，你觉得不好，可以不白跑&nbsp; <br />2012/2/2 15:18:05&nbsp; <br />但是你投了简历，那就不一样了&nbsp; <br />2012/2/2 15:18:11&nbsp; <br />你是接受选拔的&nbsp; <br />2012/2/2 15:18:15&nbsp; <br />不是我邀请面试的&nbsp; <br />2012/2/2 15:18:46&nbsp; <br />简历写得好的，一般可以不笔试，因为有东西问&nbsp; <br />2012/2/2 15:19:07&nbsp; <br />&nbsp; 15:18:46&nbsp; <br />简历写得好的，一般可以不笔试，因为有东西问&nbsp; <br /><br />嗯&nbsp; <br />2012/2/2 15:19:06&nbsp; <br />有的简历什么都看不出来，我怎么面试你，只好笔试先摸底&nbsp; <br />2012/2/2 15:19:31&nbsp; <br />招JAVA和ANDROID&nbsp; <br />2012/2/2 15:19:41&nbsp; <br />目前还在招&nbsp; <br />2012/2/2 15:20:21&nbsp; <br />其实怎么选简历&nbsp; <br />2012/2/2 15:20:30&nbsp; <br />很简单，一，正好符合要求&nbsp; <br />2012/2/2 15:20:51&nbsp; <br />2 项目经历清楚，不是要你介绍项目情况，而关键是你做了什么&nbsp; <br />2012/2/2 15:21:00&nbsp; <br />你把自己负责的说清楚&nbsp; <br />2012/2/2 15:21:08&nbsp; <br />而不是罗列各种框架名称&nbsp; <br />2012/2/2 15:21:13&nbsp; <br />是人都会SSH&nbsp; <br />2012/2/2 15:21:17&nbsp; <br />有必要写？&nbsp; <br />2012/2/2 15:21:23&nbsp; <br />你怎么知道我用SSH呢&nbsp; <br />2012/2/2 15:21:37&nbsp; <br />嗯，你要说，我做过什么&nbsp; <br />2012/2/2 15:21:50&nbsp; <br />比如XXX项目，我负责XXX模块，采用XX&nbsp; <br />2012/2/2 15:22:01&nbsp; <br />一定是最好的模块，和有特色的技术&nbsp; <br />2012/2/2 15:22:10&nbsp; <br />一般什么CRUD，写了有啥用呢&nbsp; <br />2012/2/2 15:22:24&nbsp; <br />你做过一大把甜删改查有啥好些的&nbsp; <br />2012/2/2 15:22:33&nbsp; <br />这也能说明一个人抓重点的能力&nbsp; <br />2012/2/2 15:22:41&nbsp; <br />你有那么几个点闪光&nbsp; <br />2012/2/2 15:22:54&nbsp; <br />我觉得，嗯，可以叫来详细问问&nbsp; <br />2012/2/2 15:22:57&nbsp; <br />面试机会就有了&nbsp; <br />2012/2/2 15:23:16&nbsp; <br />那笔试有啥用呢，我已经对你有兴趣点了&nbsp; <br />2012/2/2 15:23:35&nbsp; <br />只要你说的是真的，不出大问题，这事就成了&nbsp; <br />2012/2/2 15:24:23&nbsp; <br />钱也是一样的&nbsp; <br />2012/2/2 15:24:28&nbsp; <br />不是说CRUD就不要&nbsp; <br />2012/2/2 15:24:41&nbsp; <br />有时候也会招CRUD的，因为项目组要小弟&nbsp; <br />2012/2/2 15:24:57&nbsp; <br />但我叫你面试前，对你其实有了期望&nbsp; <br />2012/2/2 15:25:12&nbsp; <br />比如招你就是做CRUD的，那你要7K我都觉得贵了&nbsp; <br />2012/2/2 15:25:19&nbsp; <br />招你就是当牛人的&nbsp; <br />2012/2/2 15:25:27&nbsp; <br />你要15K，也是可以商量的&nbsp; <br />2012/2/2 15:25:39&nbsp; <br />你的简历决定了我见你之前对你的定位&nbsp; <br />2012/2/2 15:25:51&nbsp; <br />当然你吹牛皮，来了不是那么一回事&nbsp; <br />2012/2/2 15:26:01&nbsp; <br />也会让我快速失去对你的兴趣&nbsp; <br />2012/2/2 15:26:26&nbsp; <br />其实不是吹牛&nbsp; <br />2012/2/2 15:26:33&nbsp; <br />是如何让别人发生兴趣点&nbsp; <br />2012/2/2 15:26:40&nbsp; <br />一般有一个兴趣点就可以免了&nbsp; <br />2012/2/2 15:26:42&nbsp; <br />面了&nbsp; <br />2012/2/2 15:26:51&nbsp; <br />2个兴趣点，我就可以给的钱多点&nbsp; <br />2012/2/2 15:26:54&nbsp; <br />3个以上&nbsp; <br />2012/2/2 15:26:57&nbsp; <br />那是我争取你了&nbsp; <br />2012/2/2 15:27:11&nbsp; <br />一个人解决团队的一个问题，就足够了&nbsp; <br />2012/2/2 15:28:12&nbsp; <br />如果我主动对你介绍的多，证明我想要你&nbsp; <br />2012/2/2 15:28:31&nbsp; <br />如果我要你说的多，证明我还没看清楚你，又不想放弃你，想给你机会多说&nbsp; <br />2012/2/2 15:28:43&nbsp; <br />如果我就机械的和你一问一答&nbsp; <br />2012/2/2 15:28:49&nbsp; <br />基本就是出于礼貌了&nbsp; <br />2012/2/2 15:29:21&nbsp; <br />我是个部门经理&nbsp; <br />2012/2/2 15:29:34&nbsp; <br />我想说下，面试是怎么一回事&nbsp; <br />2012/2/2 15:29:43&nbsp; <br />反正这些经验没用了&nbsp; <br />2012/2/2 15:31:13&nbsp; <br />很多人简历也写的不好，说也不主动，看不清，也许你经验很足，但我招你压力很大，你想你要1W，什么都没表现，你说凭实力说话，可以试用，但我天天招人，不行就开掉&nbsp; <br />2012/2/2 15:31:21&nbsp; <br />HR怎么看我，上级如何看我&nbsp; <br />2012/2/2 15:31:50&nbsp; <br />不能这么干，所以简历和面试，你必须把闪光点总结出来&nbsp; <br />2012/2/2 15:32:14&nbsp; <br />一个项目做完，你就得想，这个项目里我最得意的作品和收获是什么&nbsp; <br />2012/2/2 15:32:20&nbsp; <br />我怎么写入简历里面&nbsp; <br />2012/2/2 15:32:26&nbsp; <br />比如某CMS项目&nbsp; <br />2012/2/2 15:32:38&nbsp; <br />你写我做了栏目管理，文章管理，&nbsp; <br />2012/2/2 15:32:44&nbsp; <br />有啥用，都是CRUD&nbsp; <br />2012/2/2 15:33:03&nbsp; <br />我写，我负责多线程静态化任务生成&nbsp; <br />2012/2/2 15:33:20&nbsp; <br />至少展示了2点，1 我知道静态化，2 我熟悉多线程&nbsp; <br />2012/2/2 15:33:36&nbsp; <br />这样，你去找CMS项目组，就比你开始写的好&nbsp; <br />2012/2/2 15:35:40&nbsp; <br />你要把技术和实际问题结合&nbsp; <br />2012/2/2 15:35:52&nbsp; <br />这样面馆好问，启发他提问&nbsp; <br />2012/2/2 15:36:01&nbsp; <br />比如我说我会多线程&nbsp; <br />2012/2/2 15:36:16&nbsp; <br />面馆怎么问，问你如何防止死锁&nbsp; <br />2012/2/2 15:36:19&nbsp; <br />是可以怎么问&nbsp; <br />2012/2/2 15:36:28&nbsp; <br />但这东西对他对你都没用&nbsp; <br />2012/2/2 15:36:43&nbsp; <br />你背一背，他也听不出错误&nbsp; <br />2012/2/2 15:36:48&nbsp; <br />但是还是不知道你会不会&nbsp; <br />2012/2/2 15:37:08&nbsp; <br />你说我用多线程做了啥，这里面为啥要多线程，多线程解决了什么实际问题&nbsp; <br />2012/2/2 15:37:16&nbsp; <br />或许他还眼睛一亮&nbsp; <br />2012/2/2 15:37:29&nbsp; <br />我的某项目可以让你做，正好啥问题，需要这样&nbsp; <br />2012/2/2 15:37:38&nbsp; <br />你让他舒服，他就让你舒服&nbsp; <br />2012/2/2 15:37:45&nbsp; <br />你和他纯理论&nbsp; <br />2012/2/2 15:37:55&nbsp; <br />那他问死你很容易&nbsp; <br />2012/2/2 15:38:12&nbsp; <br />因为他不舒服，他得挖空心思设计问题套话&nbsp; <br />2012/2/2 15:38:43&nbsp; <br />交流到了一个人必须想话题问另外一个人的时候，那么被问的人就悲剧了&nbsp; <br />2012/2/2 15:39:08&nbsp; <br />你要提供的出来话题，让双方变成讨论，那签约就是小事了&nbsp; <br />2012/2/2 15:39:11&nbsp; <br />很HAPPY了&nbsp; <br />2012/2/2 15:41:03&nbsp; <br />反正这是我的经验，我面试是这么被面的，我当面试官后，也是这样面人的&nbsp; <br />2012/2/2 15:41:17&nbsp; <br />有的人，面完他，你很高兴，希望他早点上班&nbsp; <br />2012/2/2 15:41:33&nbsp; <br />有的人，只希望赶快礼貌而客气的拒绝他&nbsp; <br /></font></p><img src ="http://www.blogjava.net/DLevin/aggbug/381984.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/DLevin/" target="_blank">DLevin</a> 2012-07-02 13:51 <a href="http://www.blogjava.net/DLevin/archive/2012/07/02/381984.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>22个免费的图表、流程图工具【转】</title><link>http://www.blogjava.net/DLevin/archive/2012/05/22/378817.html</link><dc:creator>DLevin</dc:creator><author>DLevin</author><pubDate>Tue, 22 May 2012 04:48:00 GMT</pubDate><guid>http://www.blogjava.net/DLevin/archive/2012/05/22/378817.html</guid><wfw:comment>http://www.blogjava.net/DLevin/comments/378817.html</wfw:comment><comments>http://www.blogjava.net/DLevin/archive/2012/05/22/378817.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/DLevin/comments/commentRss/378817.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/DLevin/services/trackbacks/378817.html</trackback:ping><description><![CDATA[<a href="http://sd.csdn.net/a/20120517/2805640.html">http://sd.csdn.net/a/20120517/2805640.html</a><br />感觉还不错，保留～～～<img src ="http://www.blogjava.net/DLevin/aggbug/378817.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/DLevin/" target="_blank">DLevin</a> 2012-05-22 12:48 <a href="http://www.blogjava.net/DLevin/archive/2012/05/22/378817.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>手动制作python的exe可执行程序 -- by Leo Jay</title><link>http://www.blogjava.net/DLevin/archive/2011/12/20/366823.html</link><dc:creator>DLevin</dc:creator><author>DLevin</author><pubDate>Tue, 20 Dec 2011 03:48:00 GMT</pubDate><guid>http://www.blogjava.net/DLevin/archive/2011/12/20/366823.html</guid><wfw:comment>http://www.blogjava.net/DLevin/comments/366823.html</wfw:comment><comments>http://www.blogjava.net/DLevin/archive/2011/12/20/366823.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/DLevin/comments/commentRss/366823.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/DLevin/services/trackbacks/366823.html</trackback:ping><description><![CDATA[<p>原文来自：<a href="http://wiki.woodpecker.org.cn/moin/LeoJay/PyPackage">http://wiki.woodpecker.org.cn/moin/LeoJay/PyPackage</a><br />记录下来以防以后找不到了。<br /><br /></p>
<p class="line874">Python没有内建一个编译为exe的功能。给python程序的部署带来不少的麻烦。 <span id="line-3" class="anchor"></span><span id="line-4" class="anchor"></span>
<p class="line874">所以就会出现一些py2exe之类的很不错的工具，用于自动把.py文件编译为.exe文件。 <span id="line-5" class="anchor"></span><span id="line-6" class="anchor"></span>
<p class="line874">最近抽空研究了一下手动实现类似py2exe的功能，希望加强对python的了解。 <span id="line-7" class="anchor"></span><span id="line-8" class="anchor"></span>
<p class="line874">结果还相当不错。把结果记录下来，与大家共享。 <span id="line-9" class="anchor"></span><span id="line-10" class="anchor"></span>
<p class="line867">
<h3 id="A.2BU590Bg-">原理</h3>
<p><span id="line-11" class="anchor"></span>&nbsp;</p>
<p class="line867"><strong>文中所描述的方法，基于python的以下几个功能 </strong><span id="line-12" class="anchor"></span><span id="line-13" class="anchor"></span>
<p class="line874">1. python程序运行时，会在sys.path指定的路径中查找库文件。 <span id="line-14" class="anchor"></span><span id="line-15" class="anchor"></span>
<p class="line874">2. python从2.3开始，支持从zip文件中import库(支持.py,.pyc和.pyo，但不支持.pyd) <span id="line-16" class="anchor"></span><span id="line-17" class="anchor"></span>
<p class="line874">3. python提供C API，让c语言的程序，可以很方便的调用python的程序 <span id="line-18" class="anchor"></span><span id="line-19" class="anchor"></span>
<p class="line867">
<h3 id="A.2BW56WRWtlmqQ-">实际步骤</h3>
<p><span id="line-20" class="anchor"></span>&nbsp;</p>
<p class="line867"><strong>注：假设python安装在c:\python25目录中，最后的可执行文件放到d:\dist目录中</strong> <span id="line-21" class="anchor"></span><span id="line-22" class="anchor"></span>
<p class="line874">1. 先去c:\python25\Lib目录，把所有文件都复制出来，比如复制到d:\pythonlib目录中 <span id="line-23" class="anchor"></span><span id="line-24" class="anchor"></span>
<p class="line862">2. 开一个cmd窗口，进入d:\pythonlib目录中，运行 <tt>python&nbsp;-OO&nbsp;compileall.py&nbsp;-f&nbsp;.</tt> 把lib中的.py文件都编译成.pyo文件 <span id="line-25" class="anchor"></span><span id="line-26" class="anchor"></span>
<p class="line874">3. 删除d:\pythonlib目录中所有的.py和.pyc文件，因为我们只要有.pyo文件就可以让这些库运行了。 <span id="line-27" class="anchor"></span><span id="line-28" class="anchor"></span>
<p class="line874">4. 删除目录中所有用不着的文件，比如curses，test，idlelib，msilib等，以减少生成文件的体积。 <span id="line-29" class="anchor"></span><span id="line-30" class="anchor"></span>
<p class="line874">5. 把这些库打包成一个zip文件，比如stdlib.zip，放到d:\dist目录中 <span id="line-31" class="anchor"></span><span id="line-32" class="anchor"></span>
<p class="line874">6. 把c:\python25\dlls目录中的.pyd和.dll文件，复制到d:\dist\dlls目录中，当然，删除不可能用到的一些文件_msi.pyd,_ssl.pyd等等，可以减少文件的体积 <span id="line-33" class="anchor"></span><span id="line-34" class="anchor"></span>
<p class="line862">7. 把自己写的程序，也按步骤2至步骤5所说的方法，打成一个mysrc.zip包，放到d:\dist目录中。 <strong>注意：自己写的程序的入口应该是main.pyo文件</strong> <span id="line-35" class="anchor"></span><span id="line-36" class="anchor"></span>
<p class="line874">8. 用以下C程序编译出一个可执行文件，比方说叫runpy.exe，也放到d:\dist中。 <span id="line-37" class="anchor"></span><span id="line-38" class="anchor"></span>
<p class="line867"><span id="line-39" class="anchor"></span><span id="line-40" class="anchor"></span><span id="line-41" class="anchor"></span><span id="line-42" class="anchor"></span><span id="line-43" class="anchor"></span><span id="line-44" class="anchor"></span><span id="line-45" class="anchor"></span><span id="line-46" class="anchor"></span><span id="line-47" class="anchor"></span><span id="line-48" class="anchor"></span><span id="line-49" class="anchor"></span><span id="line-50" class="anchor"></span><span id="line-51" class="anchor"></span><span id="line-52" class="anchor"></span><span id="line-53" class="anchor"></span><span id="line-54" class="anchor"></span><span id="line-55" class="anchor"></span><span id="line-56" class="anchor"></span><span id="line-57" class="anchor"></span><span id="line-58" class="anchor"></span><span id="line-59" class="anchor"></span><span id="line-60" class="anchor"></span><span id="line-61" class="anchor"></span><span id="line-62" class="anchor"></span><span id="line-63" class="anchor"></span><span id="line-64" class="anchor"></span><span id="line-65" class="anchor"></span><span id="line-66" class="anchor"></span><span id="line-67" class="anchor"></span><span id="line-68" class="anchor"></span><span id="line-69" class="anchor"></span><span id="line-70" class="anchor"></span><span id="line-71" class="anchor"></span><span id="line-72" class="anchor"></span><span id="line-73" class="anchor"></span><span id="line-74" class="anchor"></span><span id="line-75" class="anchor"></span><span id="line-76" class="anchor"></span><span id="line-77" class="anchor"></span>
<p><span id="line-78" class="anchor">&nbsp;</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">Python.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">Windows.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdlib.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img id="Codehighlighter1_92_980_Open_Image" onclick="this.style.display='none'; Codehighlighter1_92_980_Open_Text.style.display='none'; Codehighlighter1_92_980_Closed_Image.style.display='inline'; Codehighlighter1_92_980_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_92_980_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_92_980_Closed_Text.style.display='none'; Codehighlighter1_92_980_Open_Image.style.display='inline'; Codehighlighter1_92_980_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_92_980_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_92_980_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;得到当前可执行文件所在的目录</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #008000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;szPath[</span><span style="color: #000000">10240</span><span style="color: #000000">];<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;szCmd[</span><span style="color: #000000">10240</span><span style="color: #000000">];<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetModuleFileName(NULL,&nbsp;szPath,&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(szPath));<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;p&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;strrchr(szPath,&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">\\</span><span style="color: #000000">'</span><span style="color: #000000">);<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(p&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;NULL)<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_306_401_Open_Image" onclick="this.style.display='none'; Codehighlighter1_306_401_Open_Text.style.display='none'; Codehighlighter1_306_401_Closed_Image.style.display='inline'; Codehighlighter1_306_401_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_306_401_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_306_401_Closed_Text.style.display='none'; Codehighlighter1_306_401_Open_Image.style.display='inline'; Codehighlighter1_306_401_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_306_401_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_306_401_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Get&nbsp;module&nbsp;file&nbsp;name&nbsp;error!\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">p&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;设定运行时的PATH</span><span style="color: #008000"><br /></span><span style="color: #008080">22</span><span style="color: #008000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf(szCmd,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">PATH=%s\\dlls;%%PATH%%</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;szPath);<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_putenv(szCmd);<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">25</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;把sys.path设定为['.',&nbsp;'自己的源代码zip文件',&nbsp;'标准库zip文件',&nbsp;'dll目录']<br /></span><span style="color: #008080">26</span><span style="color: #008000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;然后调用main模块</span><span style="color: #008000"><br /></span><span style="color: #008080">27</span><span style="color: #008000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf(szCmd,<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">import&nbsp;sys\n</span><span style="color: #000000">"</span><span style="color: #000000"><br /></span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">sys.path=['.',&nbsp;r'%s\\mysrc.zip',&nbsp;r'%s\\stdlib.zip',&nbsp;r'%s\\dlls']\n</span><span style="color: #000000">"</span><span style="color: #000000"><br /></span><span style="color: #008080">30</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">import&nbsp;main\n</span><span style="color: #000000">"</span><span style="color: #000000">,<br /></span><span style="color: #008080">31</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;szPath,&nbsp;szPath,&nbsp;szPath);<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Py_OptimizeFlag&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">;<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Py_NoSiteFlag&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Py_Initialize();<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PyRun_SimpleString(szCmd);<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">39</span><span style="color: #000000"><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /></span></div>
<p></span>&nbsp;</p>
<p class="line874">9. 把python25.dll放到d:\dist目录中。 <span id="line-79" class="anchor"></span><span id="line-80" class="anchor"></span>
<p class="line867">
<h3 id="A.2BftNnX4vt-">结束语</h3>
<p class="line874">这样来，d:\dist目录中，一共只有4个文件加一个目录： <span id="line-82" class="anchor"></span><span id="line-83" class="anchor"></span>
<ul><li>
<p class="line891"><strong>dlls目录</strong>：用于存放所有的dll文件和pyd文件 <span id="line-84" class="anchor"></span></p></li><li>
<p class="line891"><strong>stdlib.zip文件</strong>：用于存放所有的python的.pyo文件格式的标准库 <span id="line-85" class="anchor"></span></p></li><li>
<p class="line891"><strong>mysrc.zip文件</strong>：用于存放自己写的程序。注意，自己写的程序的入口在main.pyo中。 <span id="line-86" class="anchor"></span></p></li><li>
<p class="line891"><strong>runpy.exe文件</strong>：程序的启动文件，启动后会设定python的sys.path，然后调用main模块 <span id="line-87" class="anchor"></span></p></li><li>
<p class="line891"><strong>python25.dll文件</strong>：python的核心dll，runpy.exe依赖于这个dll <span id="line-88" class="anchor"></span></p></li></ul>
<p class="line867"></p>
<hr />

<p>&nbsp;</p>
<p class="line874"><span id="line-89" class="anchor"></span>
<ul><li style="list-style-type: none">哈哈，相当的简洁明了吧。一共才4个文件一个目录，5MB都不到哦。 <span id="line-90" class="anchor"></span><span id="line-91" class="anchor"></span></li></ul>
<p class="line874">注：当然，这种打包方式第一次做的时候比较麻烦，但之后就可以只要把自己的程序打包就好了，其它的不用变。 <span id="line-92" class="anchor"></span><span id="line-93" class="anchor"></span>
<p class="line874">而且，如果自己的程序经常做改动的话，自己的程序也可以不打包，直接放到d:\dist中，反正runpy.exe启动程序的时候，只要能正常运行import main就可以了。 <span id="line-94" class="anchor"></span><span id="line-95" class="anchor"></span>
<p class="line867"></p>
<hr />

<p>&nbsp;</p>
<p class="line874"><span id="line-96" class="anchor"></span><span id="line-97" class="anchor"></span>
<p class="line862">有不少人写email给我，问我要我做的包。大家可以在这里下载基于2.5.2版本的包： <a class="attachment" title="" href="http://wiki.woodpecker.org.cn/moin/LeoJay/PyPackage?action=AttachFile&amp;do=view&amp;target=python_dist.7z">python_dist.7z</a> <span id="line-98" class="anchor"></span>以及基于3.1.2版本的包： <a class="attachment" title="" href="http://wiki.woodpecker.org.cn/moin/LeoJay/PyPackage?action=AttachFile&amp;do=view&amp;target=python31-dist.7z">python31-dist.7z</a> <span id="line-99" class="anchor"></span><span id="line-100" class="anchor"></span>
<p class="line862">注：3.1.2依赖于<a class="http" href="http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2&amp;displaylang=en">visual c++ 2008 redistributable package</a>. 如果在目标机器上没有安装，则程序运行不起来。 <span id="line-101" class="anchor"></span><span id="line-102" class="anchor"></span>
<p class="line874">解开包后，只要用自己的程序替换mysrc.zip就可以使用了。 <span id="line-103" class="anchor"></span><span id="line-104" class="anchor"></span>
<p class="line874">包里有runpy.exe和runpyw.exe两个文件。其中，runpy.exe是控制台程序，runpyw.exe是非控制台程序。这两个程序分别类似于python.exe和pythonw.exe。想让程序运行时出现一个控制台，就运行runpy.exe，如果不想出现黑黑的控制台，就运行runpyw.exe。 <span id="line-105" class="anchor"></span><span id="bottom" class="anchor"></span></p>
<p>&nbsp;</p><img src ="http://www.blogjava.net/DLevin/aggbug/366823.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/DLevin/" target="_blank">DLevin</a> 2011-12-20 11:48 <a href="http://www.blogjava.net/DLevin/archive/2011/12/20/366823.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>