(1)”Most people are too fretful, they worry too much.Success means being very patient, but aggressive when it’s time.”
看完这条可不要too aggressive哈。芒格本人曾经就因为用margin给自己带来过大麻烦。我这个朋友也喜欢用margin,非常危险。

(2)”Using [a stock’s] volatility as a measure of risk is nuts. Risk to us is 1) the risk of permanent loss of capital, or 2) the risk of inadequate return. Some great businesses have very volatile returns – for example, See’s [a candy company owned owned by Berkshire] usually loses money in two quarters of each year – and some terrible businesses can have steady results.”

(3)”I think that, every time you saw the word EBITDA [earnings], you should substitute the word “bullshit” earnings.”

(4)“Warren talks about these discounted cash flows. I’ve never seen him do one.”?”It’s true,” replied Buffett. “If the value of a company doesn’t just scream out at you, it’s too close.”

(5)”If you buy something because it’s undervalued, then you have to think about selling it when it approaches your calculation of its intrinsic value. That’s hard. But if you buy a few great companies, then you can sit on your ass. That’s a good thing.”

(6)”We bought a doomed textile mill [Berkshire Hathaway] and a California S&L [Wesco] just before a calamity. Both were bought at a discount to liquidation value.”
6,我们买过一个纺织厂(Berkshire Hathaway)和一个加州的存贷行(Wesco),这俩后来都带来了灾难。但是我们买的时候,价格都比清算价值打折还低。

(7)”For society, the Internet is wonderful, but for capitalists, it will be a net negative. It will increase efficiency, but lots of things increase efficiency without increasing profits. It is way more likely to make American businesses less profitable than more profitable. This is perfectly obvious, but very little understood.”
我也这么认为:internet 实际上是就业杀手,需要很多年才能消化。但是,如果能看懂这个变化则会非常有收获。

(8)”Virtually every investment expert’s public assessment is that he is above average, no matter what is the evidence to the contrary.” 这可是芒格说的哈。

(9)”Investing is where you find a few great companies and then sit on your ass.”

(10)”Warren spends 70 hours a week thinking about investing.”

(11)”People calculate too much and think too little.” 投资上看起来确实如此。

(12)”Whenever you think something or some person is ruining your life, it’s you. A victimization mentality is so debilitating.”

(13)”The tax code gives you an enormous advantage if you can find some things you can just sit with.”

(14)”If you’re going to buy something which compounds for 30 years at 15% per annum and you pay one 35% tax at the very end, the way that works out is that after taxes, you keep 13.3% per annum. In contrast, if you bought the same investment, but had to pay taxes every year of 35% out of the 15% that you earned, then your return would be 15% minus 35% of 15%—or only 9.75% per year compounded. So the difference there is over 3.5%. And what 3.5% does to the numbers over long holding periods like 30 years is truly eye-opening…”

(15)”The number one idea, is to view a stock as an ownership of the business [and] to judge the staying quality of the business in terms of its competitive advantage. Look for more value in terms of discounted future cash flow than you’re paying for. Move only when you have an advantage. It’s very basic. You have to understand the odds and have the discipline to bet only when the odds are in your favor.”

(16)”Failure to handle psychological denial is a common way for people to go broke. You’ve made an enormous commitment to something.You’ve poured effort and money in. And the more you put in, the more that the whole consistency principle makes you think,” Now it has to work. If I put in just a little more, then it ’all work…. People go broke that way —because they can ’t stop,rethink,and say,’ I can afford to write this one off and live to fight again. I don’t have to pursue this thing as an obsession —in a way that will break me .’ “
16,人们破产的常见原因是不能控制心理上的纠结。你花了这么多心血、这么多金钱,花的越多,就越容易这么想:“估计快成了,再多花一点儿,就能成了……” 人们就是这么破产的—-因为他们不肯停下来想想:“之前投入的就算没了呗,我承受得起,我还可以重新振作。我不需要为这件事情沉迷不误,这可能会毁了我的。”

(17)”…in terms of business mistakes that I’ve seen over a long lifetime, I would say that trying to minimize taxes too much is one of the great standard causes of really dumb mistakes. I see terrible mistakes from people being overly motivated by tax considerations. Warren and I personally don’t drill oil wells. We pay our taxes. And we’ve done pretty well, so far. Anytime somebody offers you a tax shelter from here on in life, my advice would be don’t buy it.”

(18)”I believe that we are at or near the apex of a great civilization….In 50-100 years, if we’re a poor third to some countries in Asia, I wouldn’t be surprised. If I had to bet, the part of the world that will do best will be Asia.”

(19)”To some extent, stocks are like Rembrandts. They sell based on what they’ve sold in the past. Bonds are much more rational. No-one thinks a bond’s value will soar to the moon.” “Imagine if every pension fund in America bought Rembrandts. Their value would go up and they would create their own constituency.”

(20)”It’s crazy to assume that what’s happening in Argentina and Japan is inconceivable here.”

(21)”REITs are way more suitable for individual shareholders than for corporate shareholders. And Warren has enough residue from his old cigar-butt personality that when people became disenchanted with the REITs and the market price went down to maybe a 20% discount from what the companies could be liquidated for, he bought a few shares with his personal money. So it’s nice that Warren has a few private assets with which to pick up cigar butts in memory of old times – if that’s what keeps him amused.”

(22)”Smart people aren’t exempt from professional disasters from overconfidence. Often, they just run aground in the more difficult voyages they choose, relying on their self-appraisals that they have superior talents and methods.”

(23))”The whole concept of the house advantage is an interesting one in modern money management. The terms of the managers of the private partnerships look a lot like the take of the croupier at Monte Carlo, only greater.”

(24)”There are always people who will be better at some thing than you are.You have to learn to be a follower before you become a leader.”

(25)”We all are learning, modifying, or destroying ideas all the time. Rapid destruction of your ideas when the time is right is one of the most valuable qualities you can acquire. You must force yourself to consider arguments on the other side. If you can’t state arguments against what you believe better than your detractors, you don’t know enough.”

(26)“I remember the $0.05 hamburger and a $0.40-per-hour minimum wage, so I’ve seen a tremendous amount of inflation in my lifetime. Did it ruin the investment climate? I think not.”

(27)”A lot of success in life and business comes from knowing what you want to avoid: early death, a bad marriage, etc.” 就是坚持不做不对的事情的意思。

(28)”There are two types of mistakes: 1) doing nothing[We saw it, but didn’t act on it]; what Warren calls “sucking my thumb” and 2) buying with an eyedropper things we should be buying a lot of.”

(29)”Checklist routines avoid a lot of errors. You should have all of this elementary wisdom, and you should go through a mental checklist in order to use it. There is no other procedure that will work as well.”

(30)”Litigation is notoriously time-consuming, inefficient, costly and unpredictable.”

(31)”Finding a single investment that will return 20% per year for 40 years tends to happen only in dreamland. In the real world, you uncover an opportunity, and then you compare other opportunities with that. And you only invest in the most attractive opportunities. That’s your opportunity cost. That’s what you learn in freshman economics. The game hasn’t changed at all. That’s why Modern Portfolio Theory is so asinine.”

(32)”The more hard lessons you can learn vicariously rather than through your own hard experience, the better.”
“Well, some of our success we predicted and some of it was fortuitous.”

(33)”The general assumption is that it must be easy to sit behind a desk and people will bring in one good opportunity after another — this was the attitude in venture capital until a few years ago. This was not the case at all for us — we scrounged around for companies to buy. For 20 years, we didn’t buy more than one or two per year. …It’s fair to say that we were rooting around. There were no commissioned salesmen. Anytime you sit there waiting for a deal to come by, you’re in a very dangerous seat.”
33,一般认为,最好的情形就是你坐在办公室里,然后美好的投资机会一个接一个地被送到你的面前 —- 直到几年之前,风投界的人们就是这样享受的。但是我们完全不是这样 —- 我们就跟要饭的似的到处寻找好公司来买。20年来,我们每年最多投资一到两个公司…… 说我们已经挖地三尺了都不夸张。(好机会)是没有专业推销员的。如果你坐在那里等待好机会来临,那你的座儿很危险。

(34)”Our biggest mistakes, were things we didn’t do, companies we didn’t buy.”

(35)”You can progress only when you learn the method of learning.”

(36)”It is remarkable how much long-term advantage people like us have gotten by trying to be consistently not stupid, instead of trying to be very intelligent.”

(37)”Berkshire’s past record has been almost ridiculous. If Berkshire had used even half the leverage of, say, Rupert Murdoch, it would be five times its current size.”

(38)”It took us months of buying all the Coke stock we could to accumulate $1 billion worth — equal to 7% of the company. It’s very hard to accumulate major positions.”
38,买可口可乐股票的时候我们花了几个月才攒了10亿美元的股票 — 是可口可乐总市值的7%。要攒成主要股东是很难的。

(39)”All large aggregations of capital eventually find it hell on earth to grow and thus find a lower rate of return”

(40)”If you have only a little capital and are young today, there are fewer opportunities than when I was young. Back then, we had just come out of a depression. Capitalism was a bad word. There had been abuses in the 1920s. A joke going around then was the guy who said, ‘I bought stock for my old age and it worked — in six months, I feel like an old man!’ “It’s tougher for you, but that doesn’t mean you won’t do well — it just may take more time. But what the heck, you may live longer.”
40,如果今天你的资本较少并且年轻,你的机会比我们那时候要少。我们年轻的时候刚走出大萧条,资本主义那时候是一个贬义词,在20年代对资本主义的批判更是肆虐。那时候流行一个笑话:有个人说“我买股票是为老了的时候考虑,没想到六个月就用上了!我现在已经觉得自己是老人了。”你们的环境更加艰难,但并不意味着你们做不好 — 只是要多花些时间。但是去他娘的,你们还可能活的更长呢。

(41)”Regarding the demographic trend called Baby Boomers, it’s peanuts compared to the trend of economic growth.? Over the last century, [our] GNP is up seven times.? This was not caused by Baby Boomers, but by the general success of capitalism and the march of technology.? Those trends were so favorable that little blips in the birth rate were not that significant.??We can keep social peace as long as GNP rises 3% annually – this can pay for spending by politicians.? If we ever got to stasis [no growth], then with all the promises, you’d get real tensions between the generations.? The Baby Boomers would exacerbate it, but the real cause would be lack of growth.”
41,关于所谓“婴儿潮(美国5、60年代出生)”的人口学现象,其影响相对经济增长的影响来说小很多。过去的一个世纪,美国的GNP(国民生产总值)增长了7倍。这不是婴儿潮导致的,而是由美国资本主义的成功和技术的发展带来的。这两样东西的影响太利好,婴儿潮问题相比之下就是一个小波动。只要美国的GNP每年增长3%,就能保持社会和平 — 足以覆盖政客们的花销。如果美国的发展停滞了,我敢保证,你们将会见证真切的代沟,不同代的人之间关系会很紧张。婴儿潮是这种紧张的催化剂,但是根本原因还是经济不增长。

(42)”Practically everybody overweighs the stuff that can be numbered, because it yields to the statistical techniques they’re taught in academia, and doesn’t mix in the hard-to-measure stuff that may be more important. That is a mistake I’ve tried all my life to avoid, and I have no regrets for having done that.”

(43)”You must know the big ideas in the big disciplines, and use them routinely — all of them, not just a few. Most people are trained in one model — economics, for example — and try to solve all problems in one way. You know the old saying: to the man with a hammer, the world looks like a nail. This is a dumb way of handling problems.”
43,你应该对各种学科的各种思维都有所理解,并且经常使用它们 — 它们的全部,而不是某几个。大部分人都熟练于使用某一个单一的模型,比如经济学模型,去解决所有的问题。应了一句老话:“拿锤子的木匠,看这世界就觉着像钉子。” 这是一种很白痴的做事方法。

(44)”The whole concept of dividing it up into ‘value’ and ‘growth’ strikes me as twaddle. It’s convenient for a bunch of pension fund consultants to get fees prattling about and a way for one advisor to distinguish himself from another. But, to me, all intelligent investing is value investing.”

(45)”In my whole life, I have known no wise people who didn’t read all the time – none, zero. You’d be amazed at how much Warren reads, at how much I read. My children laugh at me. They think I’m a book with a couple of legs sticking out.”

(46)”We read a lot.? I don’t know anyone who’s wise who doesn’t read a lot.? But that’s not enough: You have to have a temperament to grab ideas and do sensible things.? Most people don’t grab the right ideas or don’t know what to do with them.”

(47)”We get these questions a lot from the enterprising young. It’s a very intelligent question: You look at some old guy who’s rich and you ask, ‘How can I become like you, except faster?”

(48)”It takes almost no capital to open a new See’s candy store. We’re drowning in capital of our own that has almost no cost. It would be crazy to franchise stores like some capital-starved pancake house. We like owning our own stores as a matter of quality control”

(49)”It’s dangerous to short stocks.”

(50)”Being short and seeing a promoter take the stock up is very irritating. It’s not worth it to have that much irritation in your life.”

(51)”It would be one of the most irritating experiences in the world to do a lot of work to uncover a fraud and then at have it go from X to 3X and and have the crooks happily partying with your money while you’re meeting margin calls. Why would you want to go within hailing distance of that?”

(52)”…the cost of being a publicly traded stock has gone way, way up. It doesn’t make sense for a little company to be public anymore. A lot of little companies are going private to be rid of these burdensome requirements….”?

(53)”Well the open-outcry auction is just made to turn the brain into mush: you’ve got social proof, the other guy is bidding, you get reciprocation tendency, you get deprival super-reaction syndrome, the thing is going away… I mean it just absolutely is designed to manipulate people into idiotic behavior.”

(54)”The problem with closed bid auctions is that they are frequently won by people making a technical mistake, as in the case with Shell paying double for Belridge Oil. You can’t pay double the losing bid in an open outcry auction.”

(55)”We’re partial to putting out large amounts of money where we won’t have to make another decision.”

(56)”Understanding how to be a good investor makes you a better business manager and vice versa.”

(57)”What’s fascinating . . .is that you could now have a business that might have been selling for $10 billion where the business itself could probably not have borrowed even $100 million. But the owners of that business, because its public, could borrow many billions of dollars on their little pieces of paper- because they had these market valuations. But as a private business, the company itself couldn’t borrow even 1/20th of what the individuals could borrow.”

(58)”I constantly see people rise in life who are not the smartest – sometimes not even the most diligent. But they are learning machines; they go to bed every night a little wiser than when they got up. And, boy, does that habit help, particularly when you have a long run ahead of you.”

(59)”The basic concept of value to a private owner and being motivated when you’re buying and selling securities by reference to intrinsic value instead of price momentum – I don’t think that will ever be outdated.”

(60)”Warren and I have not made our way in life by making successful macroeconomic predictions and betting on our conclusions.”

(61)”Well, the questioner came from Singapore which has perhaps the best economic record in the history of any developing economy and therefore he referred to 15% per annum as modest. It’s not modest–it’s arrogant. Only someone from Singapore would call it modest.”

(62)”I don’t spend much time, regretting the past, once I’ve taken my lesson from it. I don’t dwell on it.”

(63)”If you took our top fifteen decisions out, we’d have a pretty average record. It wasn’t hyperactivity, but a hell of a lot of patience. You stuck to your principles and when opportunities came along, you pounce on them with vigor.”

(64)”We just throw some decisions into the ‘too hard’ file and go onto the others.”

(65)”Forgetting your mistakes is a terrible error if you are trying to improve your cognition.”

(66)”In the 1930s, there as a stretch here you could borrow more against the real estate than you could sell it for. I think that’s what’s going on in today’s private-equity world”

(67)”Mimicking the herd invites regression to the mean.”

(68)”A lot of opportunities in life tend to last a short while, due to some temporary inefficiency… For each of us, really good investment opportunities aren’t going to come along too often and won’t last too long, so you’ve got to be ready to act and have a prepared mind.”

(69)”Everywhere there is a large commission, there is a high probability of a ripoff.”

(70)”Acknowledging what you don’t know is the dawning of wisdom.”

(71)”Recognize reality even when you don’t like it – especially when you don’t like it.”
71,即使你不喜欢现实,也要承认现实 — 其实越是你不喜欢,你越应该承认现实。

(72)”We try more to profit from always remembering the obvious than from grasping the esoteric.”

(73)?“Over the long term, it’s hard for a stock to earn a much better return that the business which underlies it earns. If the business earns six percent on capital over forty years and you hold it for that forty years, you’re not going to make much different than a six percent return – even if you originally buy it at a huge discount. Conversely, if a business earns eighteen percent on capital over twenty or thirty years, even if you pay an expensive looking price, you’ll end up with one hell of a result.”

(74)”Just as a man working with his tools should know its limitations, a man working with his cognitive apparatus must know its limitations.”

(75)”Many markets get down to two or three big competitors—or five or six. And in some of those markets, nobody makes any money to speak of. But in others, everybody does very well.? Over the years, we’ve tried to figure out why the competition in some markets gets sort of rational from the investor’s point of view so that the shareholders do well, and in other markets, there’s destructive competition that destroys shareholder wealth.? If it’s a pure commodity like airline seats, you can understand why no one makes any money. As we sit here, just think of what airlines have given to the world—safe travel, greater experience, time with your loved ones, you name it. Yet, the net amount of money that’s been made by the shareholders of airlines since Kitty Hawk, is now a negative figure—a substantial negative figure. Competition was so intense that, once it was unleashed by deregulation, it ravaged shareholder wealth in the airline business.? Yet, in other fields—like cereals, for example—almost all the big boys make out. If you’re some kind of a medium grade cereal maker, you might make 15% on your capital. And if you’re really good, you might make 40%. But why are cereals so profitable—despite the fact that it looks to me like they’re competing like crazy with promotions, coupons and everything else? I don’t fully understand it.? Obviously, there’s a brand identity factor in cereals that doesn’t exist in airlines. That must be the main factor that accounts for it.And maybe the cereal makers by and large have learned to be less crazy about fighting for market share—because if you get even one person who’s hell-bent on gaining market share…. For example, if I were Kellogg and I decided that I had to have 60% of the market, I think I could take most of the profit out of cereals. I’d ruin Kellogg in the process. But I think I could do it.”
“You must have the confidence to override people with more credentials than you whose cognition is impaired by incentive-caused bias or some similar psychological force that is obviously present. But there are also cases where you have to recognize that you have no wisdom to add – and that your best course is to trust some expert.”
75,许多市场最终会形成两到三个大竞争者 —- 或者五到六个。其中有些市场里压根儿没有人能赚到什么钱。有些市场里每个竞争者都做得不错。多年以来,我们一直在研究,为什么有些市场里竞争比较理性,股东们获得的回报都不错,而有些市场里的竞争则让股东血本无归。我们举航空公司的例子来说吧,咱们现在坐在这里,可以想到航空公司们为世界作出的各种贡献 — 安全的旅行、更好的体验、能够随时飞向你的爱人,等等。但是,这个行业自从莱特兄弟的时代以来,给股东们回报的利润是负的,而且是一个巨大的负数。这个市场里的竞争是如此激烈,以至于一旦放开监管,航空公司们就开始(大降价)来损害股东们的权益。然而,在另外一些行业里,比如麦片行业,几乎所有的竞争者都混得挺舒服。如果你是一家中型的麦片生产商,你大概能有15%的资产回报率。如果你的本事特别好,甚至能达到40%。但是为什么麦片这么挣钱呢?在我看来他们整天搞各种疯狂的营销、推广、优惠券来激烈竞争,竟然还这么挣钱。我不是很明白。显然,品牌效应的因素是麦片行业有而航空行业没有的。这可能是个主要因素。或者麦片生产商们有共识,认为谁都不可以那么疯狂地竞争 —- 因为如果有一个二楞子视市场占有率如命根,比如说如果我是家乐氏的老板然后我决定要抢占60%的市场占有率,我想我可以把这个市场的大部分利润都给弄没了。这个过程中我可能会把家乐氏给毁掉。但是我想我还是可以做到(占据市场以及消灭行业利润)。你应该有信心去颠覆那些比你资深的人,条件是他们的认知被动机导致的偏见蒙蔽了、或者被类似的心理因素明显影响了。但是在另外一些情况下,你应该认识到你也许没有什么新意可想 — 你最好的选择就是相信这些领域中的专家。

(76)”In business we often find that the winning system goes almost ridiculously far in maximizing and or minimizing one or a few variables — like the discount warehouses of Costco.”
76,我们发现那些在生意中优胜的“系统”往往有些变量被近乎荒谬地最大化或者最小化 —- 比如Costco的打折仓储店。

(77)”There are worse situations than drowning in cash and sitting, sitting, sitting. I remember when I wasn’t awash in cash — and I don’t want to go back.”
77,有些情况比坐拥大量现金无处可投更糟糕。我还记得当年缺钱的情景 — 我可不想回到那个时候。

(78)”If you always tell people why, they’ll understand it better, they’ll consider it more important, and they’ll be more likely to comply.”

(79)”Spend less than you make; always be saving something. Put it into a tax-deferred account. Over time, it will begin to amount to something. This is such a no-brainer.”
79,量入而出、时刻攒钱、把钱放到可以延期交税的账户里。时间长了,你就会攒出一笔财富了。 这完全不需要动什么脑子。

(80)”I try to get rid of people who always confidently answer questions about which they don’t have any real knowledge.”

(81)”I believe in the discipline of mastering the best that other people have ever figured out. I don’t believe in just sitting down and trying to dream it all up yourself. Nobody’s that smart…”

(82)”I know someone who lives next door to what you would actually call a fairly modest house that just sold for $17 million. There are some very extreme housing price bubbles going on .”

(83)”Experience tends to confirm a long-held notion that being prepared, on a few occasions in a lifetime, to act promptly in scale, in doing some simple and logical thing, will often dramatically improve the financial results of that lifetime. A few major opportunities, clearly recognizable as such, will usually come to one who continuously searches and waits, with a curious mind that loves diagnosis involving multiple variables. And then all that is required is a willingness to bet heavily when the odds are extremely favorable, using resources available as a result of prudence and patience in the past.”

(84)”The present era has no comparable referent in the past history of capitalism. We have a higher percentage of the intelligentsia engaged in buying and selling pieces of paper and promoting trading activity than in any past era. A lot of what I see now reminds me of Sodom and Gomorrah. You get activity feeding on itself, envy and imitation. It has happened in the past that there came bad consequences.”

(85)”Our investment style has been given a name – focus investing – which implies ten holdings, not one hundred or four hundred. The idea that it is hard to find good investments, so concentrate in a few, seems to me to be an obvious idea. But 98% of the investment world does not think this way. It’s been good for us.”

(86)”You want to be very careful with intense ideology. It presents a big danger for the only mind you’re ever going to get.”

(87)”Like Warren, I had a considerable passion to get rich. “Not because I wanted Ferraris– I wanted the independence. I desperately wanted it.”

(88)”Anyone with an engineering frame of mind will look at [accounting standards] and want to throw up.”

(89)”You can progress only when you learn the method of learning.”

(90)”It’s a good habit to trumpet your failures and be quiet about your successes.”

(91)”In effect about half our spare cash was stashed in currencies other than the dollar. I consider that a non-event. As it happens it’s been a very profitable non-event.”

(92)”As for what we like least, we don’t want kleptocracies. We need a rule of law. If people are stealing from the companies, we don’t need that.”

(93)”I agree with Peter Drucker that the culture and legal systems of the United States are especially favorable to shareholder interests, compared to other interests and compared to most other countries. Indeed, there are many other countries where any good going to public shareholders has a very low priority and almost every other constituency stands higher in line.”

(94)”Berkshire in its history has made money betting on sure things.”

(95)”I don’t think there’s any business that we’ve bought that would have sold itself to a hedge fund. There’s a class of businesses that doesn’t want to deal with private-equity and hedge funds…thank God”

(96)”We’re guessing at our future opportunity cost. Warren is guessing that he’ll have the opportunity to put capital out at high rates of return, so he’s not willing to put it out at less than 10% now. But if we knew interest rates would stay at 1%, we’d change. Our hurdles reflect our estimate of future opportunity costs.”

(97)”Our ideas are so simple that people keep asking us for mysteries when all we have are the most elementary ideas.”

(98)”The idea of a margin of safety, a Graham precept, will never be obsolete. The idea of making the market your servant will never be obsolete. The idea of being objective and dispassionate will never be obsolete. So Graham had a lot of wonderful ideas.”

(99)”Ben Graham could run his Geiger counter over this detritus from the collapse of the 1930s and find things selling below their working capital per share and so on….? But he was, by and large, operating when the world was in shell shock from the 1930s—which was the worst contraction in the English-speaking world in about 600 years. Wheat in Liverpool, I believe, got down to something like a 600-year low, adjusted for inflation. the classic Ben Graham concept is that gradually the world wised up and those real obvious bargains disappeared. You could run your Geiger counter over the rubble and it wouldn’t click. … Ben Graham followers responded by changing the calibration on their Geiger counters. In effect, they started defining a bargain in a different way. And they kept changing the definition so that they could keep doing what they’d always done. And it still worked pretty well.”
99,格雷厄姆的方法就像是拿着探测器在30年代的废墟里寻找宝贝 — 股价比每股现金还低的便宜股票。但总的来说,他工作的时代是全世界还陷在二战战后恐惧症的时代,那是英语世界600年来通缩最严重的时代。利物浦的小麦价格跌到了600百年的最低值。经典的格雷厄姆理念认为世界会渐渐苏醒过来,这些便宜会消失的。你拿着那时候的探测器在现在的废墟里恐怕是找不到宝贝的。所以格雷厄姆的追随者们就调整了探测器,他们开始用现代的方法来定义宝贝。他们一直在改进探测器,来做自己擅长的事情 — 寻宝。直到现在,他们都还做得不错。

(100)”Warren and I don’t feel like we have any great advantage in the high-tech sector. In fact, we feel like we’re at a big disadvantage in trying to understand the nature of technical developments in software, computer chips or what have you. So we tend to avoid that stuff, based on our personal inadequacies. Again, that is a very, very powerful idea. Every person is going to have a circle of competence. And it’s going to be very hard to advance that circle. If I had to make my living as a musician…. I can’t even think of a level low enough to describe where I would be sorted out to if music were the measuring standard of the civilization.? So you have to figure out what your own aptitudes are. If you play games where other people have the aptitudes and you don’t, you’re going to lose. And that’s as close to certain as any prediction that you can make. You have to figure out where you’ve got an edge. And you’ve got to play within your own circle of competence.? If you want to be the best tennis player in the world, you may start out trying and soon find out that it’s hopeless—that other people blow right by you. However, if you want to become the best plumbing contractor in Bemidji, that is probably doable by two-thirds of you. It takes a will. It takes the intelligence. But after a while, you’d gradually know all about the plumbing business in Bemidji and master the art. That is an attainable objective, given enough discipline. And people who could never win a chess tournament or stand in center court in a respectable tennis tournament can rise quite high in life by slowly developing a circle of competence—which results partly from what they were born with and partly from what they slowly develop through work.”
100,巴菲特和我在高科技领域都没有什么优势。我们觉得让我们去了解软件、芯片之类的东西我们讨不着好。所以,基于这些不足,我们尽量避免这些东西。这又是一个很重要的思维。每个人都有自己的能力圈,而且这个能力圈很难增长。如果我要依靠音乐谋生的话 — 我就完蛋了。所以你应该想想自己的天资在什么地方。如果你在从事别人有天赋而你没有的工作,你肯定是要输的。没有意外。你要知道你的强项在什么地方,要在你的能力圈里面玩儿。如果你想做天下第一网球手,你可能很快发现自己没戏,有人会迅速赢你好几条街。但是如果你想做城关镇的水管承包商,可能三分之二的人都能做到。这需要一个意向和一些智力投入。但是一段时间之后你就会慢慢了解城关镇的水管行业并且渐渐掌握这门艺术了。这是一个可以达到的目标,只要有足够的付出。就是运用一些与生俱来或者后天慢慢养成的能力圈,那些即使从来没有赢过象棋比赛和网球比赛的人们也可以在生活中走向不小的成功。

(101)”Beta and modern portfolio theory and the like – none of it makes any sense to me.”
101,风险系数贝塔和现代投资组合理论都一样 — 对于我来说完全是瞎搞。

(102)”Today, it seems to be regarded as the duty of CEOs to make the stock go up. This leads to all sorts of foolish behavior. We want to tell it like it is.”

(103)”Our standard prescription for the know-nothing investor with a long-term time horizon is a no-load index fund. I think that works better than relying on your stock broker. The people who are telling you to do something else are all being paid by commissions or fees. The result is that while index fund investing is becoming more and more popular, by and large it’s not the individual investors that are doing it. It’s the institutions.”

(104)”closet indexing….you’re paying a manager a fortune and he has 85% of his assets invested parallel to the indexes. If you have such a system, you’re being played for a sucker.”

(105)”Black-Scholes is a know-nothing system. If you know nothing about value — only price — then Black-Scholes is a pretty good guess at what a 90-day option might be worth. But the minute you get into longer periods of time, it’s crazy to get into Black-Scholes.”

(106)”Black-Scholes works for short-term options, but if it’s a long-term option and you think you know something [about the underlying asset], it’s insane to use Black-Scholes.”

(107)”It’s hard to predict what will happen with two brands in a market.? Sometimes they will behave in a gentlemanly way, and sometimes they’ll pound each other.? I know of no way to predict whether they’ll compete moderately or to the death.? If you could figure it out, you could make a lot of money.”

(108)”We’ve really made the money out of high quality businesses. In some cases, we bought the whole business. And in some cases, we just bought a big block of stock. But when you analyze what happened, the big money’s been made in the high quality businesses. And most of the other people who’ve made a lot of money have done so in high quality businesses.”

(109)”A lot of share-buying, not bargain-seeking, is designed to prop stock prices up. Thirty to 40 years ago, it was very profitable to look at companies that were aggressively buying their own shares. They were motivated simply to buy below what it was worth.”

(110)”There are two kinds of businesses: The first earns 12%, and you can take it out at the end of the year. The second earns 12%, but all the excess cash must be reinvested — there’s never any cash. It reminds me of the guy who looks at all of his equipment and says, “There’s all of my profit.” We hate that kind of business. “
110,有两种生意:第一种每年挣12%,年底可以把钱拿回来;第二种每年挣12%,但是利润必须重新投入运营—永远也看不到现金。这让我想到了一个家伙,他看着手里的一大堆(不能变现的)工具装备,慨然叹曰:“这就是我的全部利润了。” 我们可不喜欢这种生意。

(111)”There are actually businesses, that you will find a few times in a lifetime, where any manager could raise the return enormously just by raising prices—and yet they haven’t done it. So they have huge untapped pricing power that they’re not using. That is the ultimate no-brainer. … Disney found that it could raise those prices a lot and the attendance stayed right up.? So a lot of the great record of Eisner and Wells … came from just raising prices at Disneyland and Disneyworld and through video cassette sales of classic animated movies… At Berkshire Hathaway, Warren and I raised the prices of See’s Candy a little faster than others might have. And, of course, we invested in Coca-Cola—which had some untapped pricing power. And it also had brilliant management. So a Goizueta and Keough could do much more than raise prices. It was perfect.”
111,有些生意你在人生中会见识几次,这些生意里,随便找个人当经理都能大幅提高利润,只需要提高商品价格 — 但是他们又没有这么做。所以他们有很多未开发的定价权。这些生意是最不需要动脑子的。迪士尼发现他们不管怎么提价,入场率都是那么高。所以艾斯纳和威尔斯(迪士尼CEO)的“杰出表现”很大部分来源于给迪士尼乐园门票提价或者给迪士尼的动画提价。在我们这儿,巴菲特和我给See’s糖果提价的速度比别人都更快一些。另外,当然了,我们也投资了可口可乐,可口可乐也是有很多未开发的定价权的。而且可口可乐还有一个很棒的管理层,所以他们的CEO可以做许多提价以外的事情。这很完美。

(112)”At Berkshire Hathaway we do not like to compete against Chinese manufacturers.”

(113)”Berkshire is in the business of making easy predictions ?If a deal looks too hard, the partners simply shelve it.”

(114)”We’re the tortoise that has outrun the hare because it chose the easy predictions.”

(115)””Warren and I avoid doing anything that someone else at Berkshire can do better. You don’t really have a competency if you don’t know the edge of it.”

(116)”Understanding both the power of compound return and the difficulty of getting it is the heart and soul of understanding a lot of things.”?

(117)”Generally speaking, it can’t be good to be running a big current account deficit and a big fiscal deficit and have them both growing. You would be thinking the end there would be a comeuppance.” “[But] it isn’t as though all the other options look wonderful compared to the US. It gives me some feeling that what I regard as fiscal misbehavior on our part could go on some time without paying the price.”

(118)”We started from such a strong position. It’s not as if the alternatives are all so great. I can understand why people would rather invest in the? U.S. Do you want to be in Europe, where 12-13% of people are unemployed and most 28-year-olds are living at home and being paid by state to do it? Or be in Brazil or Venezuela with the political instability that you fear? It’s not totally irrational that? people still like the U.S., despite its faults. Whatever misbehavior there is could go on quite a long time without a price being paid.”

(119)”Almost all good businesses engage in ‘pain today, gain tomorrow’ activities.”

(120)”No CEO examining books today understands what the hell is going on.”

(121)”Generally speaking, if you’re counting on outside directors to act [forcefully to protect your interests as a shareholder, then you’re crazy].? As a general rule in? America, boards act only if there’s been a severe disgrace. My friend Joe was asked to be on the board of Northwestern Bell and he jokes that ‘it was the last thing they ever asked me.’?I think you get better directors when you get directors who don’t need the money. ?When it’s half your income and all your retirement, you’re not likely to be very independent.? But when you have money and an existing reputation that you don’t want to lose, then you’ll act more independently.”

(122)”If mutual fund directors are independent, then I’m the lead character in the Bolshoi Ballet.”

(123)”Of course I’m troubled by huge consumer debt levels – we’ve pushed consumer credit very hard in the US.? Eventually, if it keeps growing, it will stop growing. As Herb Stein said, “If something cannot go on forever, it will stop.”? When it stops, it may be unpleasant.? Other than Herb Stein’s quote, I have no comment.”
123,我当然对现在的巨大消费债务感到担忧。我们美国一直过于致力于推进信用消费了。如果他持续增长,总有一天会停止增长的。就像赫伯·斯坦恩说的“任何不能永远前进的东西都会有停止的一刻。” 当信用消费停止增长的时候,恐怕就不好过了。我完全同意斯坦恩的说法,别无评价。

(124)”?I think it would be a great improvement if there were no D&O insurance . The counter-argument is that no-one with any money would serve on a board. But I think net net you’d be better off.”

(125)”We don’t care about quarterly earnings (though obviously we care about how the business is doing over time) and are unwilling to manipulate in any way to make some quarter look better.”

(126)”What we don’t like in modern capitalism is the expectations game. It’s not the kissing cousin of evil; it’s the blood brother.”

(127)”There are a lot of things we pass on. We have three baskets: in, out, and too tough…We have to have a special insight, or we’ll put it in the ‘too tough’ basket. All of you have to look for a special area of competency and focus on that.”

(128)”We have a history when things are really horrible of wading in when no one else will.”

(129)”We have monetized houses in this country in a way that’s never occurred before. Ask Joe how he bought a new Cadillac [and he’ll say] from borrowing on his house. We are awash in capital. [Being] awash is leading to very terrible behavior by credit cards and subprime lenders -a very dirty business, luring people into a disadvantageous position. It’s a new way of getting serfs, and it’s a dirty business. We have financial institutions, including those with big names, extending high-cost credit to the least able people. I find a lot of it revolting. Just because it’s a free market doesn’t mean it’s honorable.”
129,我们当今用房子套钱的方法以前从未出现过。你问张三他是怎么买的宝马,他会告诉你是靠抵押房子贷的款。我们现在资本过剩。资本过剩会导致人们疯狂刷信用卡和放债人发放次贷 —- 发放次贷是一个肮脏的生意。它诱惑人们前往绝地。这是一种获取奴隶的新方法,这是很脏的生意。我们有些金融机构 — 包括那些大行 —- 都在向那些弱势群体发放次贷。我觉得这种行为令人厌恶。自由市场是自由的并不意味着它就是光荣的。

(130)”We don’t believe that markets are totally efficient and we don’t believe that widespread diversification will yield a good result.? We believe almost all good investments will involve relatively low diversification. Maybe 2% of people will come into our corner of the tent and the rest of the 98% will believe what they’ve been told.”

(131)”Efficient market theory [is]? a wonderful economic doctrine that had a long vogue in spite of the experience of Berkshire Hathaway. In fact one of the economists who won — he shared a Nobel Prize — and as he looked at Berkshire Hathaway year after year, which people would throw in his face as saying maybe the market isn’t quite as efficient as you think, he said, “Well, it’s a two-sigma event.” And then he said we were a three-sigma event. And then he said we were a four-sigma event. And he finally got up to six sigmas — better to add a sigma than change a theory, just because the evidence comes in differently.And, of course, when this share of a Nobel Prize went into money management himself, he sank like a stone.”
131,市场有效论是一个很好的经济学教条,流行了很长时间,但是跟我们Berkshire Hathaway的经验相悖。事实上依靠此理论获得诺贝尔奖的其中一位经济学家也观察了我们公司好多年,人们当他面质问他,说市场恐怕不那么有效吧,不然怎么解释Berkshire的战绩,他就说我们是一个小概率的例子,有两个标准差。然后他又说我们这个例子有三个标准差。然后又说我们四个标准差。最后终于多到了六个标准差。他宁愿给我们多弄几个标准差也不愿意修改他的理论。当然了,最后当他拿获得的诺贝尔奖金自己去投资的时候,钱就泥牛入海了。

(132)”I know just enough about? thermodynamics to understand that if it takes too much fossil-fuel energy to create ethanol, that’s a very stupid way to solve an energy problem.”

(133)”It is entirely possible that you could use our mental models to find good IPOs to buy. There are countless IPOs every year, and I’m sure that there are a few cinches that you could jump on. But the average person is going to get creamed. So if you’re talented, good luck. IPOs are too small for us, or too high tech, so we won’t understand them. So, if Warren’s looking at them, I don’t know about it.”

(134)”Well envy/jealousy made, what, two out of the ten commandments? Those of you who have raised siblings you know about envy, or tried to run a law firm or investment bank or even a faculty? I’ve heard Warren say a half a dozen times, “It’s not greed that drives the world, but envy.”

(135)”Suppose, any one of you knew of a wonderful thing right now that you were overwhelmingly confident- and correctly so- would produce about 12% per annum compounded as far as you could see. Now, if you actually had that available, and by going into it you were forfeiting all opportunities to make money faster- there’re a lot of you who wouldn’t like that. But a lot of you would think, “What the hell do I care if somebody else makes money faster?” There’s always going to be somebody who is making money faster, running the mile faster or what have you. So in a human sense, once you get something that works fine in your life, the idea of caring terribly that somebody else is making money faster strikes me as insane.”
这里我看到两点:1.平常心地呆在自己能力圈内; 2. 12%是个可接受的年复合回报率。
135,假设一个场景,你知道有一个铁板钉钉没跑儿的机会可以带来12%的复合年回报。现在,假如这个机会放在你面前,但是要求你从此不再接受别的赚快钱的机会,你们中大部分人是不愿意干的。但你们中很多人也会说:“别人赚钱快为什么我要在意呢?” 这世界总有些人会赚钱比你快、跑得比你快、或者别的什么比你快。但是,从理智的角度来思考,一旦你自己找到了一件运行良好的机制能致富,还非要在意别人赚钱比你快,这在我来看就是疯了。


The Culture of Leadership












public interface ExponentialBackOffFunction <T> {
	T execute();


import static java.util.Arrays.asList;

import java.net.SocketTimeoutException;
import java.util.List;

import javax.net.ssl.SSLHandshakeException;

import lombok.extern.log4j.Log4j;

public final class ExponentialBackOff {
	private static final int[] FIBONACCI = new int[] { 1, 1, 2, 3, 5, 8, 13 };
	private static final List<Class<? extends Exception>> EXPECTED_COMMUNICATION_ERRORS = asList(
			SSLHandshakeException.class, SocketTimeoutException.class);

	private ExponentialBackOff() {

	// E(c) = Math.pow(2, c) - 1
	// 考虑到补偿时间的均匀分布,补偿时间的数学期望是所有可能性的平均值。
	// 也就是说,在c次冲突之后,补偿时隙数量在 [0,1,...,N] 中,其中 [公式] E(c) = Math.pow(2, c) - 1
	// 则补偿时间的数学期望 E(c) = (Math.pow(2, c) - 1)/2
	public static long getWaitTimeExponential(int attempt) {
		double waitTime = (Math.pow(2, attempt) - 1) / 2;
		return Math.round(waitTime * 100);
	// 这个地方使用斐波那契数去增加重试时间
	public static long getWaitTimeDefault(int attempt) {
		return FIBONACCI[attempt] * 100;

	public static <T> T execute(ExponentialBackOffFunction<T> fn) {
		for (int attempt = 0; attempt < FIBONACCI.length; attempt++) {
			try {
				return fn.execute();
			} catch (Exception e) {
				handleFailure(attempt, e);
		throw new RuntimeException("Failed to communicate.");

	private static void handleFailure(int attempt, Exception e) {
		if (e.getCause() != null && !EXPECTED_COMMUNICATION_ERRORS.contains(e.getCause().getClass()))
			throw new RuntimeException(e);

	private static void doWait(int attempt) {
		try {
			long sleepTime = getWaitTimeExponential(attempt);
			System.out.println("attempt " + attempt + " sleep " + sleepTime);
		} catch (InterruptedException e) {
			throw new RuntimeException(e);


public class Test {
	public static void main(String[] args) {
		ExponentialBackOff.execute(new Work());

class Work implements ExponentialBackOffFunction<String> {

	public String execute() {
		int a = 5 / 0;
		return a + "";


attempt 0 sleep 0
attempt 1 sleep 50
attempt 2 sleep 150
attempt 3 sleep 350
attempt 4 sleep 750
attempt 5 sleep 1550
attempt 6 sleep 3150
attempt 0 sleep 100
attempt 1 sleep 100
attempt 2 sleep 200
attempt 3 sleep 300
attempt 4 sleep 500
attempt 5 sleep 800
attempt 6 sleep 1300

Goroutines vs Threads

Here are some of the advantages of Goroutines over threads:

You can run more goroutines on a typical system than you can threads.
Goroutines have growable segmented stacks.
Goroutines have a faster startup time than threads.
Goroutines come with built-in primitives to communicate safely between themselves (channels).
Goroutines allow you to avoid having to resort to mutex locking when sharing data structures.
Goroutines are multiplexed onto a small number of OS threads, rather than a 1:1 mapping.
You can write massively concurrent servers withouth having to resort to evented programming.

You can run more of them
On Java you can run 1000’s or tens of 1000’s threads. On Go you can run hundreds of thousands or millions of goroutines.

Java threads map directly to OS threads, and are relatively heavyweight. Part of the reason they are heavyweight is their rather large fixed stack size. This caps the number of them you can run in a single VM due to the increasing memory overhead.

Go OTOH has a segmented stack that grows as needed. They are “Green threads”, which means the Go runtime does the scheduling, not the OS. The runtime multiplexes the goroutines onto real OS threads, the number of which is controlled by GOMAXPROCS. Typically you’ll want to set this to the number of cores on your system, to maximize potential parellelism.

They let you avoid locking hell
One of the biggest drawback of threaded programming is the complexity and brittleness of many codebases that use threads to achieve high concurrency. There can be latent deadlocks and race conditions, and it can become near impossible to reason about the code.

Go OTOH gives you primitives that allow you to avoid locking completely. The mantra is don’t communicate by sharing memory, share memory by communicating. In other words, if two goroutines need to share data, they can do so safely over a channel. Go handles all of the synchronization for you, and it’s much harder to run into things like deadlocks.

No callback spaghetti, either
There are other approaches to achieving high concurrency with a small number of threads. Python Twisted was one of the early ones that got a lot of attention. Node.js is currently the most prominent evented frameworks out there.

The problem with these evented frameworks is that the code complexity is also high, and difficult to reason about. Rather than “straightline” coding, the programmer is forced to chain callbacks, which gets interleaved with error handling. While refactoring can help tame some of the mental load, it’s still an issue.

Golang 的 goroutine 是如何实现的?

OKR 填写指南

OKR是一个目标管理工具。其中O指Objective,是团队或个人的工作目标;KR指Key Result,是一系列可以衡量的关键结果,用来判断Objective是否达成。在作业帮,OKR的制定和共享,是公司、团队和个人制定任务,对齐目标,协调和集中精力的重要手段。

OKR不是一个共享的工作清单或者to-do list,而是一个管理精力,自我规划的重要工具。


在每个OKR周期中,公司从CEO到全体员工都会制定自己的OKR,通常是三四个Objectives,每个Objective有3个左右的Key Results。这些OKR既有从上到下目标分解而来的,也有从基层收集的各种意见演化而来,所以OKR的制定是一个循环迭代和讨论的过程。

我们希望每一个人都制定激进的目标,这些目标看上去刚好处于 “这个周期完不成” 的边缘。事实证明,制定高目标,有助于我们取得优于普通水准的成果。 每个高目标都需要全情投入。所以OKR制定的另一方面,是严格地聚焦到重点方向,不贪多。但在选定的重点方向上,力求保证目标达成。



四、可衡量的Key Result

关键结果(Key Result,或简称KR)是用来评价目标是否达成的。考虑到这个功能,对关键结果最大的要求就是容易衡量,且直接支持目标的达成。

一些设定Key Result的窍门:

要描述产出,而不是动作。产出是指类似于“发表一篇论文”这样的表述,而动作是指“进行研究并撰写论文”这样的表述。所以当一个KR中出现 “参与”、“分析”、“辅助”这样的词汇,或者描述过程的动词特别多时,可能就有问题了。


写OKR时容易偷懒,只写一个单词,比如“收入” “DAU” “xx项目”。这样的写法,既没有说明最终要达到的状态,也很难客观打分。同时在沟通和对齐的时候,其他同事也很难看懂。类似的,“其他项目”、“重点项目”也是不可取的Objective,因为项目真的重要话,应该明确说出来要达到什么目标;而归为“其他”的目标,通常可能并不重要。



JAVA 锁优化 笔记

高效并发是JDK一个非常重要的改进,HotSpot虚拟机开发团队花费大量的精力去实现各种锁的优化技术,如适应性自旋(Adaptive Spinning)、锁消除(Lock Elimination)、锁粗化(Lock Coarsening)、轻量级锁(Lightweight Locking)和偏向锁(Biased Locking)等,这些技术都是为了线程间更高效地共享数据,以及解决竞争问题,提高程序执行效率。


自旋锁在jdk1.4.2中已经引入,只不过默认是关闭状态,可以使用-XX:+UseSpinning参数开启,在jdk1.6中已经默认开启了。自旋等待不能代替阻塞,自旋要求有多处理器,自旋虽然避免了线程切换的开销,但是需要占用处理器时间,所以会白白消耗CPU资源,如果自旋时间非常长,就会带来资源的浪费。所以,自旋等待的时间必须有一定的限度,如果自旋次数超过了限定次数还没有成功获取锁,就应当使用传统的方式去挂起线程。自旋次数默认为10次,用户可以使用参数-XX:PreBlockSpin 配置。


锁消除的主要判定依据来源于逃逸分析的数据支持,判断堆上的数据都不会逃逸出去从而被其他线程访问,那就可以吧他们当做栈上数据对待,认为数据是线程私有的,加锁操作就可以忽略。具体可以看StringBuffer 在一个方法内部 定义,作用域只在方法内,锁会安全的消除掉,编译后所有的同步操作就会直接执行。


轻量级锁并不是用来替代重量级锁的,本意是在没有多线程竞争的前提下,减少传统重量级锁使用操作系统互斥量产生的性能损耗。主要依赖虚拟机对象头数据,进行CAS操作来实现加锁和解锁操作。[备注:后续文章会详细介绍JAVA 对象的内存布局]。对象头[Mark Word]中有2bit存储锁标志位,1bit固定为0,其他状态(轻量级锁定,重量级锁定,GC标记,可偏向)
01 ——> 未锁定状态 –> 存储 对象哈希码 对象分代年龄
00 –> 轻量级锁定 –> 指向锁记录指针
10 –> 重量级锁定 –> 指向重量级锁的指针
11 –> GC标记 –> 不记录任何消息
01 –> 可偏向 –> 偏向线程ID 偏向时间戳 对象分代年龄

代码进入同步快,如果同步对象没有锁定(01 状态),虚拟机首先在当前线程的栈帧中建立一个名为锁记录(Lock Record)的空间,用于存储对象目前的Mark Word的拷贝(官方把这份拷贝加了一个Displaced 前缀,即 Displaced Mark Word),然后虚拟机使用CAS操作尝试把对象的Mark Word 更新指向 Lock Record的指针。如果操作成功线程就拥有了该对象的锁,并把对象Mark Word 的标志位修改为”00″,表示对象处于轻量级锁定状态,如果更新失败,虚拟机首先检查对象的Mark Word是否指向当前线程的栈帧,如果是说明当前线程已经拥有这个对象的锁,那就可以直接进入同步块进行执行。否则,这个锁对象已经被其他线程抢占了。如果有2个以上线程竞争,那轻量级锁就不再有效,要膨胀为重量级锁,锁标志位变为”10″,Mark Word中存储的就是指向重量级锁(互斥量)的指针,后面等待的线程也会进入阻塞状态。

解锁过程也是通过CAS操作的,如果对象的Mark Word 仍然指向着线程的锁记录,那就用CAS 操作把对象当前的Mark Word 和 线程中复制的Displaced Mark Word 替换回来。如果替换成功整个同步过程就成功了,如果替换失败,说明其他线程正在尝试获取该锁,那就再释放锁的同时唤醒其他被挂起的线程。





启用偏向锁:-XX:+UseBiasedLocking jdk1.6默认开启。
第一次获取锁需要把状态标志设置 01 (偏向模式) ,同时使用CAS操作把当前线程ID记录在Mark Word中,CAS操作成功,持有偏向锁的线程每次进入这个锁的同步块时,虚拟机没有任何同步操作(Locking,UnLocking,Update Mark Word)

偏向锁可以提高带有同步但是无竞争的程序性能。它同样是带有权衡收益(Trade Off)的优化,也就是说,并不一定对程序有利,如果程序锁竞争比较激烈,那偏向就是多余的,具体问题具体分析,有时候关闭偏向锁性能反而提升了。



内存缓存(如 Ehcache) —— 速度快,进程内可用

集中式缓存(如 Redis)—— 可同时为多节点提供服务



使用集中式缓存,由于大量的数据通过缓存获取,导致缓存服务的数据吞吐量太大,带宽跑满。现象就是 Redis 服务负载不高,但是由于机器网卡带宽跑满,导致数据读取非常慢

在遭遇问题1、2 时,很多人自然而然会想到使用 Redis 来缓存数据,因此就难以避免的导致了问题3的发生。

当发生问题 3 时,又有很多人想到 Redis 的集群,通过集群来降低缓存服务的压力,特别是带宽压力。

但其实,这个时候的 Redis 上的数据量并不一定大,仅仅是数据的吞吐量大而已。

个人觉得: 可以使用2级缓存,优先使用本地,再使用redis或者memcache的缓存,本地防止OOM可以做一些淘汰机制,刷新到redis或者memcahe中,当然这种情况就需要一些精巧的机制保证2级缓存的一致性。

节点间数据同步的方案 —— Redis Pub/Sub 和 JGroups 。当某个节点的缓存数据需要更新时,会通过 Redis 的消息订阅机制或者是 JGroups 的组播来通知集群内其他节点。当其他节点收到缓存数据更新的通知时,它会清掉自己内存里的数据,然后重新从 Redis 中读取最新数据。

为什么不用 Ehcache 的集群方案?

对 Ehcache 比较熟悉的人还会问的就是这个问题,Ehcache 本身是提供集群模式的,可以在多个节点同步缓存数据。但是 Ehcache 的做法是将整个缓存数据在节点间进行传输。如咱们前面的说的,一个页面需要读取 50K 的缓存数据,当这 50K 的缓存数据有更新时,那么需要在几个节点间传递整个 50K 的数据。这也会造成应用节点间大量的数据传输,这个情况完全不可控。

补充:当然这个单个数据传输量本身没有差别,但是 ehcache 利用 jgroups 来同步数据的做法,在实际测试过程中发现可靠性还是略低,而且 jgroups 的同步数据在云主机上无法使用。

订阅和通知模式传输的仅仅是缓存的 key 而已,因此相比 Ehcache 的集群模式,使用通知机制要传输的数据极其小,对节点间的数据通信完全不会产生大的影响。

关于谷歌极客Jeff Dean的冷笑话

在谷歌加州山景城总部,除了拉里·佩奇(Larry Page)和谢尔盖·布林(Sergey Brin),真正的牛人工程师要数杰夫·迪恩(Jeff Dean)了。

下面是谷歌员工 Heej Jones 在 Quora 上发布的关于Jeff Dean的一则故事:



慢慢认识了更多的朋友,我才知道关于Jeff Dean的一些传奇故事;一位朋友曾经惊呼道:“你和Jeff Dean 一起吃过午饭?!”。

Jeff Dean

谷歌员工都认为谷歌搜索惊人的速度都归功于Jeff Dean,因此他也成了谷歌的名人。



江湖中有一大堆关于Jeff Dean的传奇故事,都是由崇拜他的(前)谷歌员工写的。如果你了解软件工程师,懂得程序员幽默的话,那你会觉得那些故事非常有趣。

有时遇到不理解的,我们也会请求 BI首席架构师Pax Dickinson为我们解释那些笑话。

“编译器从不会给Jeff Dean警告的,Jeff Dean会给编译器警告的。”


“Jeff Dean 提交代码前会编译和运行他的代码,只是为了检验编译器和链接器有没有问题。”

解释:Jeff 的代码从不出错,他编译代码只是为了确保编译器和链接器没有bug。

“Jeff Dean 每次只给一条腿穿裤子,但是如果他有很多腿,你会发现他穿裤子的时间复杂度为O(log n)”

解释:Jeff Dean 穿裤子的算法复杂度是对数级的而不是线性级的,这样的话,如果他有很多条腿的话,就会大大节约穿裤子的时间。

“当 Richard Stallman 听说Jeff Dean的自传专属Kindle平台,他就去买了Kindle。”

解释:Richard Stallman是著名的极力反对非自由软件的人,并且从来不购买和使用Kindle。但是Jeff Dean就是这样神奇,Richard会因为想要阅读Jeff的自传而去违背自己的原则。”

“Jeff Dean 是直接写二进制机器代码的,他写源代码,是为了给其他开发人员作参考。”


“Jeff来面试谷歌时,被问到等式P=NP成立的条件,他回答,P=0 或者N=1时成立。然后在面试官哈哈大笑的时候,他看了一眼谷歌公有证书,就直接在白板上写出了相应的私钥。”

解释:“P与NP一直是计算机科学领域的一个悬而未决的问题,但是 Jeff Dean把它想成了一个代数问题,他直接用大脑根据谷歌的公有证书算出了相应的私有秘钥,这在超级计算机看来,都是不可能的事。

“X86-64 规范有几项非法指令,标志着‘私人使用’,它们其实是为Jeff Dean专用。”

解释:私有的非法CPU指令是不能被任何人使用的,但是Jeff Dean 就可以用。

“Jeff Dean 进行人体工程学评估,是为了保护他的键盘。”

解释:通常评估人体工程学是纠正坐姿,保护你的健康的,但是Jeff 却是为了保护他的键盘。

“所有的指针都是指向Jeff Dean的。”

解释:指针是C编程的核心,但是Jeff Dean 是编程世界的中心。

“在2000年末的时候,Jeff Dean 写代码的速度突然增长了40倍,原因是他把自己的键盘升级到了USB 2.0。”

解释:是键盘和计算机之间接口的速度影响了Jeff Dean 的编码速度。

原文链接: businessinsider 翻译: 伯乐在线 – JingerJoe
译文链接: http://blog.jobbole.com/51607/

DeviceEventEmitter – react-native

关于 DeviceEventEmitter 的文档说明不足,这里通过源码,记录下相关内容。


import { DeviceEventEmitter } from 'react-native';


1 addListener – 添加事件监听(常用)

   * Adds a listener to be invoked when events of the specified type are
   * emitted. An optional calling context may be provided. The data arguments
   * emitted will be passed to the listener function.
   * TODO: Annotate the listener arg's type. This is tricky because listeners
   *       can be invoked with varargs.
   * @param {string} eventType - Name of the event to listen to
   * @param {function} listener - Function to invoke when the specified event is
   *   emitted
   * @param {*} context - Optional context object to use when invoking the
   *   listener
addListener( eventType: string, listener: Function, context: ?Object)


 DeviceEventEmitter.addListener('COUSTOM_EVENT_TYPE', (e) => {

2 once – 一次性监听,联想 jquery 的 once

   * Similar to addListener, except that the listener is removed after it is
   * invoked once.
   * @param {string} eventType - Name of the event to listen to
   * @param {function} listener - Function to invoke only once when the
   *   specified event is emitted
   * @param {*} context - Optional context object to use when invoking the
   *   listener
  once(eventType: string, listener: Function, context: ?Object)

3 removeAllListeners – 移除所有的事件监听

   * Removes all of the registered listeners, including those registered as
   * listener maps.
   * @param {?string} eventType - Optional name of the event whose registered
   *   listeners to remove
  removeAllListeners(eventType: ?string)

说明。可选参数 eventType是为了移除指定事件类型的监听

4 removeCurrentListener – 在事件回调调用期间移除监听

   * Provides an API that can be called during an eventing cycle to remove the
   * last listener that was invoked. This allows a developer to provide an event
   * object that can remove the listener (or listener map) during the
   * invocation.
   * If it is called when not inside of an emitting cycle it will throw.
   * @throws {Error} When called not during an eventing cycle
   * @example
   *   var subscription = emitter.addListenerMap({
   *     someEvent: function(data, event) {
   *       console.log(data);
   *       emitter.removeCurrentListener();
   *     }
   *   });
   *   emitter.emit('someEvent', 'abc'); // logs 'abc'
   *   emitter.emit('someEvent', 'def'); // does not log anything


var subscription = emitter.addListenerMap({
     someEvent: function(data, event) {

5 removeSubscription – 移除指定的订阅

   * Removes a specific subscription. Called by the `remove()` method of the
   * subscription itself to ensure any necessary cleanup is performed.
  removeSubscription(subscription: EmitterSubscription)

6 listeners – 返回指定事件类型的所有监听者

   * Returns an array of listeners that are currently registered for the given
   * event.
   * @param {string} eventType - Name of the event to query
   * @returns {array}
  listeners(eventType: string): 

7 emit – 触发某个事件 (常用)

   * Emits an event of the given type with the given data. All handlers of that
   * particular type will be notified.
   * @param {string} eventType - Name of the event to emit
   * @param {...*} Arbitrary arguments to be passed to each registered listener
   * @example
   *   emitter.addListener('someEvent', function(message) {
   *     console.log(message);
   *   });
   *   emitter.emit('someEvent', 'abc'); // logs 'abc'
  emit(eventType: string)


emitter.addListener('someEvent', function(message) {

emitter.emit('someEvent', 'abc'); // logs 'abc'

8 removeListener – 移除指定事件类型的监听

   * Removes the given listener for event of specific type.
   * @param {string} eventType - Name of the event to emit
   * @param {function} listener - Function to invoke when the specified event is
   *   emitted
   * @example
   *   emitter.removeListener('someEvent', function(message) {
   *     console.log(message);
   *   }); // removes the listener if already registered
  removeListener(eventType: String, listener)