Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Garbage Collection Time?

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.

like image 373
Bitterblue Avatar asked Apr 17 '13 15:04

Bitterblue


People also ask

What is garbage collection time?

The more live objects are found, the longer the suspension, which has a direct impact on response time and throughput. This fundamental tenet of garbage collection and the resulting effect on application execution is called the garbage-collection pause or GC pause time.

How often does Java garbage collect?

That is, every time you allocate a small block of memory (big blocks are typically placed directly into "older" generations), the system checks whether there's enough free space in the gen-0 heap, and if there isn't, it runs the GC to free up space for the allocation to succeed.

What causes long garbage collection time in Java?

Java Garbage Collectors implement a generational garbage collection strategy that categorizes objects by age. Having to mark and compact all the objects in a JVM is inefficient. As more and more objects are allocated, the list of objects grows, leading to longer garbage collection times.

How do I fix long garbage collection time?

High Object Creation Rate A high garbage collection rate will increase the GC pause time as well. Thus, optimizing the application to create fewer objects is THE EFFECTIVE strategy to reduce long GC pauses. This might be a time-consuming exercise, but it is 100% worth doing.


1 Answers

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

like image 143
Ivan Senic Avatar answered Sep 27 '22 21:09

Ivan Senic