This is why’s 85th original article


Writing middleware often does two things:

  • 1. Lazy loading. The loaded items are cached in memory.
  • 2. Count the number of calls and intercept the concurrency.

It’s such a small feature, nine times out of ten people on the team make mistakes.


The above sentence is not said by me, but by Liang Fei in his blog.


Who is Liang Fei?

According to the online public information, Liang Fei, pseudonym virtual pole.

Joined Alibaba in 2009, responsible for the development of middleware, author of Dubbo open source distributed service framework, author of HTTL open source template engine.

In 2012, I joined Tmall, responsible for the technical team of Tmall APP, and witnessed the whole process of the wireless transformation of Tmall Double 11.

Keen to participate in the open source community construction, and spread architectural design concepts such as servitization, SOA, framework design and mobile applications.

Here’s what I found on his personal blog:

https://www.iteye.com/blog/javatar-287026

Last Friday, I went to Hangzhou for an interview. I flew there in the morning and came back in the evening, so I was in a hurry and the plane was late. It was almost 1:00 PM when I got there. After the interview, I followed several acquaintances around, and the atmosphere of learning and communication was very good. I received the Offer on Tuesday. It seems that HR is very efficient. It is good. I have been busy submitting my resignation application these days, and I am still a little reluctant to leave the company I have been working for for nearly three years. The company has given me a lot of development opportunities, and the leaders have been very kind to me. I really appreciate them. But now the new company development opportunities are better, I do not want to give up, I hope to do better in the new position, ha ha, the running account is here.

This blog post was posted on December 24, 2008.

He said last Friday, Dec. 19, 2008. Within one day, I flew from Shenzhen to Hangzhou, interviewed for one hour, and flew back to Shenzhen from Hangzhou. Four days later, I received the offer from Ali.

At that time, Liang Fei only from the hunan Institute of Science and Technology software school out of the gate less than three years.

The entry date in the article is January 8, 2009.

From then on, ali started a 12-year upgrade to fight monsters, from P5 all the way to P9.

As we all know, Ali can reach P9, it is no longer a matter of ability, it belongs to the ancestral heritage.

Liang fei was already a P9 in 2016.

Of all the labels above, he is probably best known as the founder of Dubbo.

1015 days after Liang Fei joined Ali, at 23:06 on October 20, 2011, Dubbo made his first call in the open source community:


Nine modules, 669 files, were what would eventually become the prototype of Apache’s top open source project.

The night of October 20, 2011 is destined to be a memorable one for Liang Fei.

He went on to make 13 submissions:


Dubbo finally got his first tag at 5:25 the next morning: 2.0.7.

During this period, I also took time to inform the official media to send a microblog:


And he himself, at noon the next day, announced it on his blog:


Why did Dubbo choose this day to open source?

I think it’s in time for Qcon in two days:


That day was the beginning of Dubbo’s true public exposure to both praise and ridicule.

I went through a lot of trouble to find the PPT from that conference nearly 10 years ago, and the first page is:


Ten years later, Baiyun Dog, Dubbo walked out of Ali, has truly flown into the ordinary home.

In the past ten years, the data on PPT, in terms of total amount, is just like the sales volume of Singles’ Day, which has doubled many times.

But then I thought, this is Ali 10 years ago, a billion calls a day, that’s a lot of technology people will not touch traffic in a lifetime.

At the same time, I also found many familiar pictures in PPT, such as this one:


On the left is the current Dubbo website and on the right is a POWERPOINT presentation from Qcon 10 years ago.

Ten years have passed, when these two pictures are framed together, I wonder if the “old picture” on the right has an old father’s delight.

If the image above isn’t too strong for you, take a look at this:


On the left is the official website and on the right is PPT.

Ten years later, the overall design has not changed a bit.

I don’t know what you’re thinking when you look at this, but to me, it’s awesome.

An overall design of 10 years ago, unexpectedly in the Internet industry changing with each passing day, a trace of unchanging standing down.

This is the wisdom of a group of engineers crystallization.

Dubbo’s first powerpoint presentation was 55 pages long, and included many designs that look outdated a decade later.

I’m not going to show you one by one, but for those of you who are interested, you can see how to get it at the end of the article.

Finally, here’s a photo of the original Dubbo team:


Java concurrent programming common sense

Remember that sentence at the beginning of this article?

https://www.iteye.com/blog/javatar-1963774


The PPT link here is not working, and I searched and found one after all.

It’s 18 pages. Let me show you one by one.

Some places are pure knowledge, some places are code.

Anyway, I think I see what I need to say. I’ll give a brief description below the picture.

Start.









Explain a little bit about what’s on this page.

Here are a few commands I’ve used in previous articles:

I think I know the answer to a technical question that’s been nagging me for 122 days.

Here it is:


So, I knew there was a hole in this place.

If you paste the command directly, this error will be thrown:

Java HotSpot(TM) 64-Bit Server VM warning: printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output


Because you are missing a file called HSdis-amd64.dll (Windows platform).

You need to place this file in the jre/bin/server directory:


Then replace the command with this:

-XX:+UnlockDiagnosticVMOptions

-XX:+PrintAssembly

-XX:CompileCommand=print,*AtomicInteger.incrementAndGet

Execute the program again, and there is assembly output:


Let’s focus on the parameter CompileCommand.

This parameter is used to customize compilation requirements, such as specifying that a method is not JIT compiled, or only the specified method is compiled, and so on.

Here’s how it works:

-XX:CompileCommand=command,method[,option]

Command has the following options:

  • Exclude, skips compiling the specified method
  • Compileonly, only compiles the specified method
  • Inline /dontinline, which sets whether to inline the specified method
  • Print, prints the generated assembly code
  • Break, when the JVM runs in debug mode, sets a breakpoint at the start of method compilation
  • Quiet, do not print the compiler option specified after this command via -xx :CompileCommand
  • Log: records compilation logs of the specified method. If this parameter is not specified, compilation logs of all methods are recorded
  • Other commands, option, help

Such as the usage of powerpoint – XX: CompileCommand = print, * AtomicInteger incrementAndGet

Contains is printed AtomicInteger. IncrementAndGet method to generate assembly code.


Buffer line alignment, this should be a need to master the knowledge, belongs to the program optimization of strange technology.

I am here for the interview.

The purpose of alignment is to address the occurrence of False Sharing.

Do not know false sharing friends, it is suggested to understand.

The source of the PPT example is:

com.google.code.yanf4j.util.LinkedTransferQueue.PaddedAtomicReference


Note that in Java8, a more elegant solution is provided: @sparkled annotation.



This is also a very classic evolution of the singleton pattern.

There are altogether four singleton modes on the PPT, and we look at them one by one.


This is the hungrier singleton that we all know about. By pre-initialization, the concurrency problem is solved and the singleton is guaranteed.

The key word here is the final static keyword.

The author also used blue to distinguish, which must be meaningful.

Class loading process:

Load, validate, prepare, parse, initialize.

Take this example:

public static int value =123

The value variable, with only the static modifier, is assigned an initial value of 0 in the preparation phase.

123 is assigned during initialization.

But when we add a final modifier:

public final static int value =123

The value variable is assigned 123 in the preparation phase.

So, you think about the above hungry man, is it the same truth?

And this knowledge point, in “deep understanding Java virtual machine” book inside, write or very clear.

But hangry has a distinct disadvantage: it is initialized whether the application is in use or not.

It’s not elegant.

So, come to the second procedure, full Chinese style.


Initialization is performed only when needed.

But how do you keep threads safe?

Ensure thread-safety by adding the synchronized keyword to methods?

But is it really safe?

This is probably one of the interviewer’s favorite questions.

If you didn’t know before, you probably never thought you’d get a half-initialized object.

In short, the new Singleton() is not atomic, so instance is not fully initialized when the if condition is met.

This leads to the following procedure:


The legendary double check lock.

One of the most “overlooked” aspects of this program is the volatile keyword.

Without the volatile keyword, the program is invalid.

Also, it should be noted that Liang Fei notes a JDK1.5 + here.

Why is that?

The answer can be found on page 287 of Java Concurrent Programming In Action:


In this book, the idiom for double-checking locks is: infamous.

And as you can see from the picture, the driving force for the emergence of this mode is no longer there and is not an efficient optimization measure.

Now, I think double-check locking is mostly used in the interview process.

It is not an efficient optimization measure, but it is a high frequency test point, why?

It’s the eight-part essay that kills people.

And then there’s the last one, which the author favors:


The scientific name of this operation is “Singleton Pattern Solution based on Class Initialization.”

The JVM acquires a lock during the Class initialization phase, after the Class is loaded and before it is used by a thread.

This lock ensures that when multiple threads initialize the same class, only one thread can successfully initialize it.

The principle of this approach is clearly explained in section 3.8.4 of the Art of Concurrent Programming in Java.

What? You don’t have either of these books?

Go ahead and get one. It’s quite good. I’ve recommended it many times before.


The forehead…

I didn’t get this page either.

I think there must be a context, but Liang Fei did not write it in the PPT.

I’m seeing things in a fog.



Only CountDownLatch and CyclicBarrier are written here.

There is also an important and commonly used tool class: Semaphore.

If you don’t know, check out this article:

Shit! Semaphore has such a big pit!

If you don’t know all three.

Catch! Tight! Go to! To learn!





Print it out, stick it next to your computer, read it aloud and recite it.