Difference between JMX garbage collection and System.gc ()?

When I studied the behavior of my application in VisualVM, I came across this and was puzzled, I thought that the JMX call to execute the garbage collection would have the same functions as the call System.gc(), however, in all environments I tried it on, the JMX call always leads to lesser use of the heap and then to a call System.gc(), which is functionally the difference?

enter image description here

You can see the final drop - I manually clicked on the “Run GC” button, my usage decreased slightly than in regular collections of the system. Thoughts on why this might be?

I tried this in several environments, leaving collections to the system and manually calling System.gc(), and every time a JMX call will clear much more.

, , JMX , , ?

+4
2

(- , - ) - Sun MemoryMXBean, sun.management.MemoryImpl:

public void gc() {
    Runtime.getRuntime().gc();
}

http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/sun/management/MemoryImpl.java#MemoryImpl.gc%28%29

System.gc():

public static void gc() {
    Runtime.getRuntime().gc();
}

http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/lang/System.java#System.gc%28%29

, , , .

+4

, , MemoryMXBean.gc() System.gc().

MemoryMXBean.gc()

void gc() . gc() : System.gc() . : System.gc()

http://docs.oracle.com/javase/7/docs/api/java/lang/management/MemoryMXBean.html

System.gc()

public static void gc() . gc , Java , . , Java , .

System.gc() :

Runtime.getRuntime(). gc() . : Runtime.gc()

http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#gc()

Runtime.gc()

public void gc() . , Java , , . , . gc " ". , gc .

System.gc() .

http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#gc()

0

Source: https://habr.com/ru/post/1615680/


All Articles