Tag: puzzle

java.util.concurrent.LinkedBlockingQueue中的奇怪代码

所有! 我在LinkedBlockingQueue中发现了奇怪的代码: private E dequeue() { // assert takeLock.isHeldByCurrentThread(); Node h = head; Node first = h.next; h.next = h; // help GC head = first; E x = first.item; first.item = null; return x; } 谁能解释为什么我们需要局部变量h? 它对GC有什么帮助?