OpenJDK#39;s LinkedBlockingQueue implementation: Node class and GC(OpenJDK 的 LinkedBlockingQueue 实现:Node 类和 GC)
问题描述
我对 OpenJDK 的 LinkedBlockingQueue 实现(在 java.util.concurrent 中)中的 Node 类的结构有点困惑.
I'm a little confused by the structure of the Node class in OpenJDK's implementation of LinkedBlockingQueue (in java.util.concurrent).
我已经复制了以下节点类的描述:
I've reproduced the description of the node class below:
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").
Specifically, I'm confused on the 2nd choice for next ("this Node, meaning successor is head.next").
这似乎和dequeue方法直接相关,长这样:
This seems to be directly related to the dequeue method, which looks like:
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;
}
所以我们已经移除了当前的 head,并且我们将它的 next 设置为本身来帮助 GC".
So we've removed the current head, and we're setting its next to be itself to "help GC".
这对 GC 有什么帮助?对 GC 有多大帮助?
How does this help GC? How helpful is it to GC?
推荐答案
我问了代码的作者 Doug Lea 教授,他说它减少了GC 留下浮动垃圾的机会.
I asked Professor Doug Lea, author of the code, and he said that it reduces the chances of GC leaving floating garbage.
一些关于漂浮垃圾的有用资源:
Some useful resources on floating garbage:
http://www.memorymanagement.org/glossary/f.html#浮动的垃圾
http://java.sun.com/docs/hotspot/gc1.4.2/#4.4.4.%20Floating%20Garbage|outline
http://blog.johantibell.com/2010/04/generational-garbage-collection-and.html
这篇关于OpenJDK 的 LinkedBlockingQueue 实现:Node 类和 GC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:OpenJDK 的 LinkedBlockingQueue 实现:Node 类和 GC
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01