Java geek
Related reading:
Java Concurrent programming (1) Knowledge map Java concurrent programming (2) Atomic Java concurrent programming (4) Sequential Java concurrent programming (5) Introduction to Java concurrent programming (6) Synchronized usage Java Concurrency programming Introduction (7) Easy to understand wait and Notify and use scenarios Java concurrency programming Introduction (8) Thread lifecycle Java concurrency programming Introduction (9) Deadlock and deadlock bit Java concurrency programming Introduction (10) lock optimization Introduction to Concurrent Programming in Java (11) Flow limiting scenarios and Spring Flow Limiting scenarios Introduction to Concurrent programming in Java (12) Producer and Consumer Patterns – Introduction to Concurrent programming in Java with code templates (13) Read/write lock and cache templates (14) CountDownLatch application scenarios Introduction to Concurrent Programming (CyclicBarrier) Introduction to Concurrent programming (CyclicBarrier) Introduction to Concurrent programming in Java (CyclicBarrier) Introduction to Concurrent programming in Java (CyclicBarrier) Introduction to Concurrent programming in Java (CyclicBarrier) Introduction to Concurrent programming in Java (CyclicBarrier) Introduction to Concurrent programming in Java (CyclicBarrier) Introduction to Concurrent programming in Java (CyclicBarrier) Introduction to Concurrent programming in Java (CyclicBarrier) Introduction to Concurrent programming in Java (CyclicBarrier Java Concurrent programming Introduction (19) Asynchronous task scheduling tool CompleteFeature Java concurrent programming Introduction (20) Common locking scenarios and locking tools
First, visibility
Each CPU on a multi-core host has its own cache. When operating on a memory variable, you need to load the variable from the memory to the CPU cache, and then update the variable from the CPU cache to the memory. If multiple threads operate on different cpus at the same time, the data displayed may be different. As shown in figure:
Second, solve the visibility problem
If variable visibility is to be resolved: 1. Variables are to be modified with the volatile keyword 2. Operation method synchronization
The above solutions are described in detail later.
end.
<– Read the mark, left like!