java - OpenJDK 的 LinkedBlockingQueue 实现 : Node class and GC

标签 java concurrency garbage-collection queue java.util.concurrent

<分区>

我对 OpenJDK 的 LinkedBlockingQueue(在 java.util.concurrent 中)实现中的 Node 类的结构有点困惑。

我在下面复制了节点类的描述:

static class Node<E> {
    E item;

    /**
     * One of:
     * - the real successor Node
     * - this Node, meaning the successor is head.next
     * - null, meaning there is no successor (this is the last node)
     */
    Node<E> next;

    Node(E x) { item = x; }
}

具体来说,我对 next 的第二个选择感到困惑(“这个节点,意思是后继者是 head.next”)。

这似乎与dequeue方法直接相关,它看起来像:

private E dequeue() {
    // assert takeLock.isHeldByCurrentThread();
    // assert head.item == null;
    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;
}

所以我们已经删除了当前的头,我们将其下一个设置为它自己以“帮助 GC”。

这对 GC 有何帮助?对GC有多大帮助?

最佳答案

关于java - OpenJDK 的 LinkedBlockingQueue 实现 : Node class and GC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10106191/

相关文章:

java - 查询 @ElementCollection 的内容。 Hibernate 标准方式

java - 二维字符数组的格式化

java - 如何在 Java HashMap 中放入多个字符串值

haskell - Haskell 中可变但可锁定的数据结构?

c - 如何在 C 中同时运行两个子进程?

java - 从回调中设置 future

multithreading - GC 无法在 Windows 上使用 fork-emulation 回收内存

java - Dataframe 未保存到 Cassandra 中

java - Apache POI 超出了 GC 开销限制

java - 从数组列表 java 中删除/删除对象