Ali was asked 16 volatile questions on both sides, desperately supplementing jvm, multithreading, and high concurrency

For Java, I think of multi-threading every time I interview. The problem of multi-threading is basically impossible. I need to ask the volalite keyword, but I never expected that a volatile keyword can generate 16 consecutive questions! See how many answers you can answer?

What does the volatile keyword mean?

Do you know where the volatile keyword is used? What problem was solved?

What is the relationship between volatile and JMM?

What is order rearrangement? What is the relationship between volatile and instruction rearrangement?

What is a memory barrier? What is the relationship between volatile and memory barriers?

What is happens-before? What does volatile have to do with it?

If the server is a single CPU, does using volatile affect the program?

There are two statements, the first is for ordinary writing, the second is for volatile writing, are other threads visible to the first ordinary writing?

Will volatile int i;i++ operations have thread safety issues?

Can volatile replace CAS?

Why does the state in AQS use CAS and need volatile?

What is Unsafe.putOrderedObject? Can it replace volatile?

Can you consider CAS + volatile = synchronized?

To solve the visibility problem, do I need volatile if I use synchronized?

Use volatile to write a lazy singleton pattern and explain why it is written like this.

Use volatile to write a producer consumer program.

After reading so many questions, it’s not difficult for us to come to a truth. Although there are various variants of volatile, they are inseparable from his principle.

1. What exactly is volatile?

2. What problem does volatile solve?

3. How does volatile solve these problems?

If you understand these three questions, the above questions are actually very easy to answer.

Interviewers who like to ask about the volatile keyword have a certain foundation in most cases, because volatile is an entry point. Going to the bottom can cut into the Java Memory Model (JMM), and go in the direction of concurrency and cut into Java concurrent programming. Of course, further investigation will involve the underlying operations of JVM, bytecode operations, and singletons.

So people who know how to ask questions have a way. So, let’s take a look at the overall design of the volatile keyword: memory visibility (JMM characteristics), atomicity (JMM characteristics), prohibition of instruction rearrangement, thread concurrency, and the difference with synchronized... and then dig deeper. , May involve bytecode, JVM, etc.

For multithreading and jvm, these two are also the focus of the interview in the current interview process. Here are some information for you, I hope it will be helpful to you

Multithreading

Documentation:

Source code interpretation of multithreading

Ali was asked 16 volatile questions on both sides, desperately supplementing jvm, multithreading, and high concurrency

Multi-threaded interview documents

Ali was asked 16 volatile questions on both sides, desperately supplementing jvm, multithreading, and high concurrency

Knowledge map

Ali was asked 16 volatile questions on both sides, desperately supplementing jvm, multithreading, and high concurrency

video

Ali was asked 16 volatile questions on both sides, desperately supplementing jvm, multithreading, and high concurrency

If you need this information, follow + like, click here to see how to get it

jvm

Documentation

Ali was asked 16 volatile questions on both sides, desperately supplementing jvm, multithreading, and high concurrency

Knowledge map

Ali was asked 16 volatile questions on both sides, desperately supplementing jvm, multithreading, and high concurrency

video

Ali was asked 16 volatile questions on both sides, desperately supplementing jvm, multithreading, and high concurrency

If you need this information, follow + like, click here to see how to get it

Guess you like

Origin blog.csdn.net/lyl5454/article/details/112463982