Java multithreading is the fourth article in this series.

Continue our Java multithreading series of articles, today to talk about the concept, this article should be the last basic concepts, and then directly into the topic of Java multithreading, in the following article if there is a concept that needs to be taken out separately to tell the concept of the supplement.

This article focuses on Blocking and non-blocking.

You must learn your first skill when you go to work

When I was working on a project in school, I basically developed it independently. Each person developed a part to divide the workload in a way that minimized the communication cost. In the workplace, it is almost impossible to arrange work simply by minimizing the docking cost. There are more and more factors to consider. Various cross-group, cross-department, and even cross-workplace work, which brings communication cost and various blocking problems of work docking.

When new people just enter the workplace, they are not familiar with everything, and when they do some docking work outside the group, they will encounter all kinds of problems, especially now there are all kinds of distributed architecture, the students who used to develop Web background will develop JSP pages, but now the front and back end are separated. Imagine this scenario.

Xiao Ming was born in the front end of learning, just entered the workplace, do the first requirement is login and registration interface, need to connect with a writing background colleague Xiao Dong, Xiao Dong is responsible for the development of login and registration of the background logic. Xiaoming developed the login interface, ready to docking with Xiaodong joint login function, then Xiaodong replied that he just had a production bug in the follow-up, has not been developed, then xiaoming how to do?

There are two ways to do this:

  1. Dry waiting for xiao Dong to develop a good login background, and then he tune.

  2. The development of the registration interface, the development process and then always ask the small east login background interface is done, if the small east is done, and then to docking.

What are the key differences between the two approaches? For Xiao Dong, there is no difference, all he can do is to achieve his feature points as early as possible. The main concern is xiaoming, the first approach, Xiaoming has done a login interface, and then wait for xiaodong’s login background interface, if xiaodong wants to develop an afternoon, then Xiaoming will do nothing in the afternoon, this situation is blocked, xiaoming’s other tasks because the login interface did not docking synch, and has been blocked; The second approach, xiao Ming know login small east didn’t implement backend interface, set out to do the registration screen function, then every hour with small east confirm login backend interface development is completed, until the login background was small east development interface, started the docking alignment, this kind of situation is blocked, not login interface docking alignment doesn’t affect the xiao Ming’s development progress, Coordinate when you can, and accomplish the other tasks at hand when you can’t.

Maybe some students make the mistake of relying on someone else because they haven’t done it yet, and then they take the first step and wait until they’ve done it. Occasionally steal lazy, if it has been such a state of work, it is not good for the students who have just entered the workplace, and this is known by the boss is very bad. If a requirement is blocked, do other work first. If no other work is on hand, give feedback to your boss and move on to other tasks. Follow up on the progress of the blocked requirement.

The following is a flowchart to describe these two concepts:

blocking

non-blocking

Do you understand blocking and non-blocking better by looking at the diagram above?

Boss calls the shots

If you were the boss, or xiaoming’s leader, what would you ask Xiaoming to do? The first way or the second way? If you support the first approach, please contact me. Is your company still hiring?

Recommended reading

You can eat fast food and learn serial, parallel, and concurrency

Make a cup of tea and learn asynchrony

How much do we know about the process?

Design patterns seen and forgotten, forgotten and read?

If you reply “Design Mode”, you can get the ebook “One Story one Design Mode”

Think the article is useful to help forward & praise, thank you friends!