java 使用 Jconsole 解决内存泄漏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4181847/
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
Using Jconsole for Memory Leak
提问by Silent Walker
I'm trying to diagnose some memory issues in our J2EE server. I've setup jconsole on our live server and I'm trying to monitor the status of the tomcat server through it. I've a quick question about the Threads tab in jconsole. I can see a thread named Finalizer in the threads list. The 'Total blocked' number in this thread keeps on increasing. For example, it's now 4,049, an hour ago it was 3,867.
我正在尝试诊断 J2EE 服务器中的一些内存问题。我已经在我们的实时服务器上设置了 jconsole,我正在尝试通过它监视 tomcat 服务器的状态。我有一个关于 jconsole 中的线程选项卡的快速问题。我可以在线程列表中看到一个名为 Finalizer 的线程。此线程中的“总被阻止”数量不断增加。例如,现在是 4,049,一小时前是 3,867。
Name: Finalizer
State: WAITING on java.lang.ref.ReferenceQueue$Lock@1b79cfd
Total blocked: 4,049 Total waited: 1,579
Name: Finalizer
State: WAITING on java.lang.ref.ReferenceQueue$Lock@1b79cfd
Total blocked: 4,049 Total waited: 1,579
What does this thread mean? Is it somehow related to the GC? I've downloaded a heap dump where it shows number of objects pending for finalization is zero.
这个线程是什么意思?它与GC有某种关系吗?我已经下载了一个堆转储,它显示待完成的对象数量为零。
The max heap size of my server is 200MB at the moment, the heap size remains between 100 and 150 MB and when I click on 'Perform GC', I can see some heap space getting freed. However this doesn't change the amount of memory taken by this tomcat process in windows task manager, which is consuming over 700 MB right now.
目前我的服务器的最大堆大小为 200MB,堆大小保持在 100 到 150 MB 之间,当我单击“执行 GC”时,我可以看到一些堆空间被释放。然而,这并没有改变这个 tomcat 进程在 windows 任务管理器中占用的内存量,它现在消耗了 700 MB 以上。
Any tips on how I should go about it will be much appreciated. Please ask me questions if you need further info on my server setup.
任何关于我应该如何去做的提示将不胜感激。如果您需要有关我的服务器设置的更多信息,请向我提问。
Thanks in advance.
提前致谢。
采纳答案by Silent Walker
I think I've found the answer to my question. The 'Total blocked' and 'Total waited' are simply counts for the number of times the thread waited or was blocked. JConsole is taking this information from ThreadInfo.
我想我已经找到了我的问题的答案。'Total blocks' 和 'Total waited' 只是线程等待或被阻塞的次数的计数。JConsole 正在从ThreadInfo获取此信息。
Blocked count is the total number of times that the thread blocked to enter or reenter a monitor. I.e. the number of times a thread has been in the java.lang.Thread.State.BLOCKED state.
Waited count is the total number of times that the thread waited for notification. i.e. the number of times that a thread has been in the java.lang.Thread.State.WAITING or java.lang.Thread.State.TIMED_WAITING state.
阻塞计数是线程被阻塞以进入或重新进入监视器的总次数。即线程处于 java.lang.Thread.State.BLOCKED 状态的次数。
Waited count 是线程等待通知的总次数。即线程处于 java.lang.Thread.State.WAITING 或 java.lang.Thread.State.TIMED_WAITING 状态的次数。
回答by Opty
Name: Finalizer State: WAITING on java.lang.ref.ReferenceQueue$Lock@1b79cfd Total blocked: 4,049 Total waited: 1,579
名称:Finalizer 状态:WAITING on java.lang.ref.ReferenceQueue$Lock@1b79cfd 总阻塞:4,049 总等待:1,579
The ReferenceQueue is maintaining a reference for all unused objects (waiting for finalization), in other words there is 4049 objects waiting for a garbage collection.
ReferenceQueue 为所有未使用的对象维护一个引用(等待终结),换句话说,有 4049 个对象在等待垃圾回收。
When hunting for memory leaks, be sure to do a full GC (or many GC until nothing can't be reclaimed) before doing the dump
在寻找内存泄漏时,请确保在执行转储之前执行完整的 GC(或多次 GC,直到无法回收任何内容)
回答by Faisal Feroz
The windows task manager shows the virtual memory size and is most of the time not accurate. I have seen this a lot of time, what JConsole shows as the footprint is the right memory footprint.
Windows 任务管理器显示虚拟内存大小,并且大部分时间都不准确。我已经看过很多次了,JConsole 显示的内存占用是正确的内存占用。
For more information regarding JConsole check here.
有关 JConsole 的更多信息,请查看此处。
回答by chzbrgla
Looks like a Deadlock to me: http://download.oracle.com/javase/tutorial/essential/concurrency/deadlock.html
对我来说看起来像是死锁:http: //download.oracle.com/javase/tutorial/essential/concurrency/deadlock.html
Do you have any synchronized methods that might be waiting infinitely?
您是否有任何可能无限等待的同步方法?