Some time ago, I realized the distributed lock function based on Redis through the tools found on the Internet on the code block for sending SMS
Corresponding link https://www.cnblogs.com/chy/p/9391602.html
I want to take a closer look at the weekend.
After that, what is depressed is why the built-in java will fail in a distributed environment. (It's all my own low opinion)
Think about it: In the case of a single machine, using Syncronized or lock to implement the lock mechanism is no problem, and there is no problem with single-process multi-threaded synchronization.
In a single-process system, when there are multiple threads that can change a variable (variable shared variable) at the same time, it is necessary to synchronize the variable or code block so that it can be executed linearly to eliminate concurrent modification when modifying this variable. variable.
In the case of Dai's distributed situation, it becomes multi-process and multi-threaded, and can your jvm control it? (I don't know why you want to talk about jvm)
At this time, Java's built-in lock will not be able to achieve concurrency.
But you can use other tools, such as Redis, which is inherently single-threaded. (Why are people born this way, people are designed like this)
I think even if it is multi-process, all need to pass Redis, but Redis is inherently thread-safe, is there any problem?