Understanding of blocking methods and non-blocking methods in LinkedBlockingQueue

Recently I am learning java concurrency and learned the source code of the LinkedBlockingQueue class. The
book says that the null parameter poll method is non-blocking:
Insert picture description here
My confusion is that the method clearly uses an exclusive lock, but why is it still non-blocking?
Insert picture description here
Explanation:

The author's blocking/non-blocking is discussed based on the characteristics of the blocking queue, not the thread characteristics. Here, non-blocking means that when the blocking queue is empty, null is returned directly, and blocking means that when the blocking queue is empty, the method blocks until there is Return after the data.
The author here says that this method is non-blocking, because
before acquiring the lock, it will make an if judgment based on the queue status, and then return. Therefore, it is non-blocking.
Insert picture description here
Let's look at the put method: we
Insert picture description here
can find that the put method does not perform if judgment on the queue attributes, and directly enters the lock operation.
Therefore, the put method is blocked.

Did you lose school?

Guess you like

Origin blog.csdn.net/Brave_heart4pzj/article/details/114361085