Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get time spent in garbage collector

I'd like to know how to get the time spent in GC. I think it is possible because newrelic provides this information on jvm monitoring. Thanks

like image 841
mravey Avatar asked Mar 17 '23 03:03

mravey


2 Answers

For hotspot jvm start jvm with -XX:+PrintGCDetails and it will start logging gc events which includes time spent

if you want to redirect it to file

-Xloggc:/home/someuser/app/logs/jvm/gc.log -verbose:gc -XX:+PrintGCDateStamps -XX:+PrintGCDetails

http://www.oracle.com/technetwork/java/javase/community/vmoptions-jsp-140102.html

like image 175
jmj Avatar answered Mar 18 '23 18:03

jmj


If you want to capture the information in your program, then you could do it using MXBeans. like

List<GarbageCollectorMXBean> list = ManagementFactory
                .getGarbageCollectorMXBeans();
        for (GarbageCollectorMXBean bean : list) {
            System.out.println(bean.getCollectionTime());
        }

More Information.

like image 27
K139 Avatar answered Mar 18 '23 18:03

K139