java 了解引用处理程序线程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7658670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Understanding the Reference Handler thread
提问by Leonardo
I am continuing my path to deep understanding of Java Thread. Unfortunately my Java Certification didn't cover that part, so the only way of learning is to post a series of dumb questions. With so many years of Java Development, I am sometimes wondering how much I still have to learn :-)
我正在继续深入了解 Java Thread。不幸的是,我的 Java 认证没有涵盖那部分,所以唯一的学习方法是发布一系列愚蠢的问题。经过这么多年的 Java 开发,我有时想知道我还需要学习多少 :-)
In particular my attention is now with the reference handler thread.
我现在特别注意参考处理程序线程。
"Reference Handler" daemon prio=10 tid=0x02da3400 nid=0xb98 in Object.wait() [0x0302f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x1aac0320> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:485)
at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
- locked <0x1aac0320> (a java.lang.ref.Reference$Lock)
Now some questions are following, for some of them I know the answer, but I am not posting it, because I would like to hear someone else opinions:
现在有一些问题,其中一些我知道答案,但我不发布它,因为我想听听其他人的意见:
- What is the Reference Handler thread supposed to do ?
- A thread dump should be considered bottom up, why does the stack trace start with locked, shouldn't the lock statement appears at least after the thread has run ?
- What does "Native Method" means ?
- Why "Unknown Source", in which case the thread dump cannot recall the source code ?
- Lastly the waiting on and locked has the same , why ?
- Reference Handler 线程应该做什么?
- 线程转储应该被认为是自下而上的,为什么堆栈跟踪以锁定开始,至少在线程运行后不应该出现锁定语句?
- “本地方法”是什么意思?
- 为什么“未知源”,在这种情况下线程转储无法调用源代码?
- 最后等待和锁定是一样的,为什么?
as usual, I kindly ask to answer all the questions, so that I can mark answered.
像往常一样,我恳请回答所有问题,以便我可以标记为已回答。
采纳答案by Joachim Sauer
- I suspectit handles running finalizers for the JVM. It's an implementation detail and as such not specified in the JVM spec.
- This only means that the
java.lang.ref.Reference$Lock
was locked in the method mentioned in the line precedingit (i.e inReferenceHandler.run()
. - "Native Method" simply means that the method is implemented in native (i.e. non-Java) code (think JNI).
- Unknown Source only means that the
.class
file doesn't contain any source code location information (at least for this specific point). This can happen eitherwhen the method is a synthetic one (doesn't look like it here), or the class was compiled without debug information. - When a thread waitson some object, then it musthave locked that object at some point down the call trace, so you can'treally have a
waiting on
without a correspondinglocked
.
- 我怀疑它会为 JVM 处理运行终结器。这是一个实现细节,因此未在 JVM 规范中指定。
- 这仅意味着
java.lang.ref.Reference$Lock
被锁定在它之前的行中提到的方法中(即在ReferenceHandler.run()
. - “本机方法”仅仅意味着该方法是在本机(即非 Java)代码中实现的(想想 JNI)。
- 未知源仅意味着该
.class
文件不包含任何源代码位置信息(至少对于此特定点)。发生这种情况无论是当该方法是合成的(不像在这里),或者类没有调试信息被编译。 - 当一个线程等待某个对象,那么它必须已经锁定该对象在某些时候下来呼叫跟踪,所以你不能真的有
waiting on
没有相应的locked
。
回答by Peter Lawrey
1) The Finalizer Thread calls finalizer methods. The Reference Thread has a similar purpose.
1) 终结器线程调用终结器方法。参考线程也有类似的目的。
http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Core/lang/java/lang/ref/Reference.java.htm
http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Core/lang/java/lang/ref/Reference.java.htm
The OpenJDK source states its is a
OpenJDK 源代码声明它是一个
High-priority thread to enqueue pending References
高优先级线程排队挂起的引用
The GC creates a simple linked list of references which need to be processed and this thread quickly adds them to a proper queue. The reason this is done in two phases is that the GC does nothing but find the References, this thread calls code which handles those references e.g. Call Cleaners, and notifies ReferenceQueue listeners.
GC 创建需要处理的引用的简单链接列表,该线程快速将它们添加到适当的队列中。这样做分两个阶段完成的原因是 GC 只查找引用,该线程调用处理这些引用的代码,例如 Call Cleaners,并通知 ReferenceQueue 侦听器。
2) A lock is acquired for a synchronized method before it is entered.
2) 同步方法在进入之前获取锁。
3-5) covered by Joachim ;)
3-5) 被约阿希姆覆盖 ;)
回答by Mac
Wow, too deep for me. I can only answer one or two of your questions.
哇,对我来说太深了。我只能回答你的一两个问题。
"Native Method" simply means the implementation of that method is in some native (i.e. C or C++) library. Once the call stack has "gone native", the JVM can no longer monitor it. No way for it to provide additional stack information.
“本机方法”只是意味着该方法的实现是在一些本机(即 C 或 C++)库中。一旦调用堆栈“变为原生”,JVM 就无法再监视它。它无法提供额外的堆栈信息。
"Unknown Source" likely means the code was compiled with optimization turned on and debugging info turned off (-g
flag?). This eliminates the file/line information from the .class file.
“未知来源”可能意味着代码是在打开优化和关闭调试信息的情况下编译的(-g
标志?)。这消除了 .class 文件中的文件/行信息。