Strange code in java.util.concurrent.LinkedBlockingQueue
问题 All! I found strange code in LinkedBlockingQueue: private E dequeue() { // assert takeLock.isHeldByCurrentThread(); Node<E> h = head; Node<E> first = h.next; h.next = h; // help GC head = first; E x = first.item; first.item = null; return x; } Who can explain why do we need local variable h? How can it help for GC? 回答1: To better understand what happens let's see how the list looks like after executing the code. First consider an initial list: 1 -> 2 -> 3 Then h points to head and first to h