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
基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01