In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the principle of CAS in Java". In daily operation, I believe that many people have doubts about the principle of CAS in Java. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubt of "what is the principle of CAS in Java?" Next, please follow the editor to study!
CAS has three operands, the memory value V, the old expected value A, and the new value B to be modified. If and only if the expected value An and the memory value V are equal, the memory value V is modified to B. This is an optimistic locking idea, and he believes that no other thread will modify him before it is modified.
The flaw of CAS: the ABA problem. CAS checks whether the value has changed when the value is updated, and performs the update operation if it has not changed. But if it turns out to be A, becomes B, and then becomes A, then CAS won't know that the value has changed. But it actually changed. The solution to the ABA problem is to use the version number. Append the version number to the variable, and add the version number + 1 for each variable update. Then A-B-A will become A1-B2-A3.
At this point, the study of "what is the principle of CAS in Java" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.