Abstractqueuedsynchronizer source code analysis of Java concurrency series (exclusive mode)
In the previous Java concurrency series [1] - summary analysis of abstractqueuedsynchronizer source code analysis, we introduced some basic concepts of abstractqueuedsynchronizer, mainly talked about how to implement the queue area of AQS, what are exclusive mode and shared mode, and how to understand the waiting state of nodes. Understanding and mastering these contents is the key to subsequent reading of AQS source code, so it is recommended that readers read my last article first and then look back at this article, which is easier to understand. In this chapter, we will introduce how a node enters the synchronization queue in exclusive mode and what operations it will perform before leaving the synchronization queue. AQS provides three ways to obtain locks in exclusive mode and shared mode: do not respond to thread interrupt acquisition, respond to thread interrupt acquisition, and set timeout acquisition. The overall steps of the three methods are roughly the same, with only a few differences. Therefore, the implementation of one method is similar to that of others. In this article, I will focus on the acquisition method that does not respond to thread interrupts, and the other two methods will also talk about the inconsistencies.