views:

294

answers:

7

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

can it because of GC running?

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

Thanks

+5  A: 

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.

jens
+1 for jconsole. You'll see a saw tooth graph of memory usage, showing when the GC's kick in. You can even trigger a manual GC if you like. I doubt you'll find this is GC rlated though.
Jim Ferrans
+8  A: 

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

Martin v. Löwis
and -XX:+PrintGCDetails
Mercer Traieste
+4  A: 

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.

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.

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.

280Z28
This is only true for small applications, which might be the case here. As soon as you scale up memory usage and therefore GC can easily become a problem. In most cases it is more about the number of garbage collections that about the time it takes a single GC.
jens
If by small you mean less than *a gig or two*, then maybe?
280Z28
+2  A: 

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).

Joey
+1  A: 

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).

It complements and enhances jconsole!

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

Thorbjørn Ravn Andersen
+1 for jvisualvm, which is amazing for finding memory leaks.
Zarkonnen
+1  A: 

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.

Carlos
A: 

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

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.

theoverture