Clean Java

There is always a bigger game

How to print GC/Garbage Collector log of JVM?

leave a comment »

You would want to print the GC log sometime to figure out the memory usage of your 
application. You can start the JVM with "-verbose:gc -XX:+PrintGCDetails" option 
to print the GC log.

package org.sanju;

import java.util.Map;
import java.util.WeakHashMap;

public class GCLogExample {

	public static void main(String args[]){
		Map map = new WeakHashMap();
		for(;;){
			map.put(Math.random(), Math.random());
		}
	}
}


Console output
--------------
[GC [DefNew: 896K->64K(960K), 0.0037925 secs] 896K->758K(5056K), 0.0038260 secs] 
[Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC [DefNew: 960K->64K(960K), 0.0050690 secs] 1654K->1632K(5056K), 0.0051052 secs] 
[Times: user=0.02 sys=0.00, real=0.01 secs] 
[GC [DefNew: 960K->64K(960K), 0.0049930 secs] 2528K->2439K(5056K), 0.0050293 secs] 
[Times: user=0.00 sys=0.00, real=0.01 secs] 
[GC [DefNew: 960K->63K(960K), 0.0053488 secs] 3335K->3244K(5056K), 0.0053847 secs] 
[Times: user=0.00 sys=0.00, real=0.00 secs] 
Advertisements

Written by cleanjava

July 5, 2011 at 11:30 pm

Posted in java

Tagged with , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: