In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What is the function of the synchronized keyword? in view of this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
The synchronized keyword solves the synchronization of accessing resources between multiple threads, and the synchronized keyword ensures that the method or block of code modified by it can only be executed by one thread at any time.
In addition, in earlier versions of Java, synchronized was a heavyweight lock, which was inefficient because the monitor lock (monitor) was implemented on the Mutex Lock of the underlying operating system, and the thread of Java was mapped to the native thread of the operating system. If you want to suspend or wake up a thread, you need the help of the operating system, and the operating system needs to switch from user mode to kernel state when switching between threads. The transition between this state takes a relatively long time, and the time cost is relatively high, which is the reason why the early synchronized is inefficient. Fortunately, after Java 6, Java officials have greatly optimized synchronized from the JVM level, so the current synchronized lock efficiency is also very good. JDK1.6 introduces a lot of optimization to the implementation of lock, such as spin lock, adaptive spin lock, lock elimination, lock coarsening, bias lock, lightweight lock and so on to reduce the cost of lock operation.
The answer to the question about the role of the synchronized keyword is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
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.