Take the 2-minute tour ×

I have a very performance sensitive application in Java. (I know I should actually use C or something else. But it's Java now.) I'm trying to avoid creating and throwing away objects. Now I need to know how much garbage collecting is going on still.

How can I find out ?

If possible I would like to have a sort of number in milliseconds or nanoseconds something that doesn't require installation of more software.

share|improve this question
Just a heads up that C is not hands-down better than Java - it depends on how you compare them. This is a good comparison I found, the bottom line is that C is better than Java for memory footprint and for numerically intensive programs, while Java has better multi-threading support. A research paper I read several years ago found that (if you let Java's heap grow to 4x the size of the C heap) there was no performance difference between the two languages for many Sourceforge programs. –  Zim-Zam O'Pootertoot Apr 17 '13 at 15:22
possible duplicate of Tuning garbage collections for low latency –  jschoen Apr 17 '13 at 20:32
add comment

4 Answers

You can use VisualVm for this, it is exactly what you need.
As you can see below you have GC activity which is very useful:

enter image description here

Beside the GC Activity you have a lot of details there like : heap usage, cpu usage, object instances usage etc.

share|improve this answer
add comment

You can use tools like VisualVM to monitor application activity. Make sure you are using appropriate GC alogorithms.

Oracle JVM provides multiple types of Garbage Collectors:

  • The throughput collector
  • The concurrent low pause collector
  • The incremental (sometimes called train) low pause collector:

Read more on these collectors here.

share|improve this answer
+1 nice suggestion about collector types :) –  Stephan Apr 17 '13 at 15:11
+1 Note: for low GC programs, VisualVM will create more garbage than your application. For this I use YourKit, which is not free. I would start with VisualVM. –  Peter Lawrey Apr 17 '13 at 15:14
There is also a plugin for VisualVM called VisualGC which shows what is happening for each heap space in real time. blogs.oracle.com/klc/entry/visualgc_plugin_for_visualvm –  Aaron Apr 17 '13 at 15:35
add comment

Jprofiler ,which Enables both memory profile to assess memory usage and dynamic allocation leaks and CPU profiling to assess thread conflicts.

share|improve this answer
add comment

Or you can let JVM print the GC activity.. These settings I have:

-verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -XX:+PrintTenuringDistribution -Xloggc:logs/gc.log

GC activity is printed to a file logs/gc.log..

share|improve this answer
add comment

Your Answer


