我可以检测垃圾收集器何时工作?

时间:2021-07-19 01:34:02

Am working on a swing app. I will experiance slowness after continuous half an hour of use.

我正在开发应用程序。经过半小时的使用后,我会慢慢体验。

can it because of GC running?

可以吗,因为GC运行?

How can i find when the garbage collector runs through any jdk 1.5 commandline option?

如何找到垃圾收集器何时运行任何jdk 1.5命令行选项?

Thanks

7 个解决方案

#1


When you start Java with -XX:+PrintGC, it will print messages whenever it garbage-collects.

当您使用-XX:+ PrintGC启动Java时,它会在垃圾收集时打印消息。

#2


You can use jconsole.exe, which can be found in the bin directory of your jdk. It shows you a lot of details about your running JVM.

您可以使用jconsole.exe,它可以在您的jdk的bin目录中找到。它向您展示了有关运行JVM的大量详细信息。

#3


It's highly unlikely that the GC is causing observable problems. Once upon a time Java had a horribly slow GC that gave it a near-permanent bad reputation. That time is past.

GC不太可能导致可观察到的问题。曾几何时,Java有一个非常缓慢的GC,它给它带来了近乎永久的坏名声。那个时光已经过去了。

What exactly is the slowness? A GC should really never take more than a fraction of a second, even for the rare full collection pass.

究竟什么是缓慢的? GC应该永远不会超过一秒钟,即使是罕见的完整收集通行证。

Edit: Even if the GC is running a measurable amount, it's likely only a symptom of the problem. Whatever code is placing that much demand on the GC would internally cause more slowness than the GC will.

编辑:即使GC运行可测量的数量,它也可能只是问题的症状。无论什么代码在GC上放置那么多的需求都会导致内部比GC更慢。

#4


I strongly doubt it's the GC you are seeing. As 280Z28 points out, the GC runs pretty fast usually (though can still kill performance if you're doing something wrong). Are you using the program in that time? If not, maybe you're a little low on memory and it got paged out? (leaving Eclipse running for longer than maybe half a day without using it results in a state I can't work anymore with it. On systems with little memory it might happen sooner).

我强烈怀疑这是你看到的GC。正如280Z28指出的那样,GC通常运行速度非常快(但如果你做错了什么,它仍然可以扼杀性能)。你在那个时候使用该程序吗?如果没有,也许你的内存有点低,它被分页了? (让Eclipse运行的时间超过半天而不使用它会导致我无法使用它的状态。在内存很少的系统上可能会更早发生)。

#5


The simplest way to investigate this if you use recent JDK is jvisualvm which allow you to attach to a running process. You can then see garbage collections, memory usage and profile if needed. (It is essentially the corresponding NetBeans functionality available as a standalone applciation in the JDK).

如果使用最近的JDK,最简单的方法是使用jvisualvm,它允许您附加到正在运行的进程。然后,您可以根据需要查看垃圾收集,内存使用和配置文件。 (它本质上是相应的NetBeans功能,可用作JDK中的独立应用程序)。

It complements and enhances jconsole!

它补充和增强了jconsole!

(But what you describe may be excessive GC's caused by a memory leak in your program. Use jvisualvm to figure out)

(但是你所描述的可能是你的程序中存在内存泄漏导致GC过多。使用jvisualvm搞清楚)

#6


GC itself probably is not the problem. However, if you have a memory leak, it might result in GC using all CPU trying to clear memory.

GC本身可能不是问题。但是,如果您有内存泄漏,可能会导致GC使用所有CPU尝试清除内存。

#7


As everyone has mentioned previously, GC is almost certainly not the problem.

正如大家之前提到的那样,GC几乎肯定不是问题所在。

I'd try something like YJP (Your Java Profiler, free for 30 days) to profile your application and find out what is slowing down. A memory leak is a very possible cause.

我会尝试使用YJP(你的Java Profiler,免费使用30天)来分析你的应用程序并找出正在放慢速度的东西。内存泄漏是一个非常可能的原因。

#1


When you start Java with -XX:+PrintGC, it will print messages whenever it garbage-collects.

当您使用-XX:+ PrintGC启动Java时,它会在垃圾收集时打印消息。

#2


You can use jconsole.exe, which can be found in the bin directory of your jdk. It shows you a lot of details about your running JVM.

您可以使用jconsole.exe,它可以在您的jdk的bin目录中找到。它向您展示了有关运行JVM的大量详细信息。

#3


It's highly unlikely that the GC is causing observable problems. Once upon a time Java had a horribly slow GC that gave it a near-permanent bad reputation. That time is past.

GC不太可能导致可观察到的问题。曾几何时,Java有一个非常缓慢的GC,它给它带来了近乎永久的坏名声。那个时光已经过去了。

What exactly is the slowness? A GC should really never take more than a fraction of a second, even for the rare full collection pass.

究竟什么是缓慢的? GC应该永远不会超过一秒钟,即使是罕见的完整收集通行证。

Edit: Even if the GC is running a measurable amount, it's likely only a symptom of the problem. Whatever code is placing that much demand on the GC would internally cause more slowness than the GC will.

编辑:即使GC运行可测量的数量,它也可能只是问题的症状。无论什么代码在GC上放置那么多的需求都会导致内部比GC更慢。

#4


I strongly doubt it's the GC you are seeing. As 280Z28 points out, the GC runs pretty fast usually (though can still kill performance if you're doing something wrong). Are you using the program in that time? If not, maybe you're a little low on memory and it got paged out? (leaving Eclipse running for longer than maybe half a day without using it results in a state I can't work anymore with it. On systems with little memory it might happen sooner).

我强烈怀疑这是你看到的GC。正如280Z28指出的那样,GC通常运行速度非常快(但如果你做错了什么,它仍然可以扼杀性能)。你在那个时候使用该程序吗?如果没有,也许你的内存有点低,它被分页了? (让Eclipse运行的时间超过半天而不使用它会导致我无法使用它的状态。在内存很少的系统上可能会更早发生)。

#5


The simplest way to investigate this if you use recent JDK is jvisualvm which allow you to attach to a running process. You can then see garbage collections, memory usage and profile if needed. (It is essentially the corresponding NetBeans functionality available as a standalone applciation in the JDK).

如果使用最近的JDK,最简单的方法是使用jvisualvm,它允许您附加到正在运行的进程。然后,您可以根据需要查看垃圾收集,内存使用和配置文件。 (它本质上是相应的NetBeans功能,可用作JDK中的独立应用程序)。

It complements and enhances jconsole!

它补充和增强了jconsole!

(But what you describe may be excessive GC's caused by a memory leak in your program. Use jvisualvm to figure out)

(但是你所描述的可能是你的程序中存在内存泄漏导致GC过多。使用jvisualvm搞清楚)

#6


GC itself probably is not the problem. However, if you have a memory leak, it might result in GC using all CPU trying to clear memory.

GC本身可能不是问题。但是,如果您有内存泄漏,可能会导致GC使用所有CPU尝试清除内存。

#7


As everyone has mentioned previously, GC is almost certainly not the problem.

正如大家之前提到的那样,GC几乎肯定不是问题所在。

I'd try something like YJP (Your Java Profiler, free for 30 days) to profile your application and find out what is slowing down. A memory leak is a very possible cause.

我会尝试使用YJP(你的Java Profiler,免费使用30天)来分析你的应用程序并找出正在放慢速度的东西。内存泄漏是一个非常可能的原因。