In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shows you the role of AQS ReentLock, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
What is a fair lock and what is an unfair lock?
Fair lock: the thread that goes to the critical section first acquires the lock first than the thread that goes later to the critical area.
Unfair lock: the thread that goes to the critical section first may not acquire the lock first than the thread that goes later to the critical section.
How to realize fair lock and unfair lock?
The fair lock puts the competing thread on a queue, and as long as the thread holding the lock is finished, the thread of the next queue is awakened to acquire the lock. The implementation of the unfair lock is also very simple, that is, the thread first tries to acquire the lock. If the lock is acquired, the synchronous code block is executed. If the lock is not acquired, the thread is placed in the queue. So the difference between a fair lock and an unfair lock is whether the thread attempts to acquire the lock when it executes the synchronous block of code.
Why create queues? Can't the thread just keep trying to acquire the lock?
Always trying to acquire a lock is a spin lock, which is resource-consuming. Multiple threads are spinning all the time, and most of them are competitive failures, so no one will do that.
The above is the role of AQS's ReentLock. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.